1
我需要將其他UIWindow
添加到我的應用程序。這UIWindow
應始終儘管設備的方向定位在屏幕的右下角,這裏的草圖: 在iOS中的UIScreen中定位UIWindow
我試圖繼承一個UIWindow這樣才能夠設置大小和窗口的邊緣:
@interface MyWindow : UIWindow
@property (nonatomic) CGSize size;
@property (nonatomic) CGFloat margin;
@end
@implementation MyWindow
- (id)initWithSize:(CGSize)size andMargin:(CGFloat)margin {
self.size = size;
self.margin = margin;
return [self initWithFrame:[self calculateFrame]];
}
- (CGRect)calculateFrame {
return CGRectMake([[UIScreen mainScreen] bounds].size.width-self.size.width-self.margin, [[UIScreen mainScreen] bounds].size.height-self.size.height-self.margin, self.size.width, self.size.height);
}
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self assignObservers];
}
return self;
}
-(void)assignObservers {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(statusBarDidChangeFrame:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
}
- (void)statusBarDidChangeFrame:(NSNotification *)notification {
[self setFrame:[self calculateFrame]];
}
@end
一切都很好啓動!無論在初始啓動方面是什麼新的UIWindow
位置都是正確的。但是,當我旋轉設備 - 我的窗戶變得瘋狂,它跳轉到意想不到的位置,我不知道爲什麼。
請幫忙!
有人嗎?請,我真的需要幫助... – oleynikd