Objective c 无法在状态栏、uiwindow、objective C顶部显示视图
我尝试通过执行以下操作在状态栏顶部添加覆盖: ViewController实现Objective c 无法在状态栏、uiwindow、objective C顶部显示视图,objective-c,ios7,uiwindow,Objective C,Ios7,Uiwindow,我尝试通过执行以下操作在状态栏顶部添加覆盖: ViewController实现 - (IBAction)addViewOnTop:(id)sender { StatusBarOverlayWindow *overlay = [[ACStatusBarOverlayWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 20)]; overlay.hidden = NO; [overlay makeKeyAndVisible];
- (IBAction)addViewOnTop:(id)sender {
StatusBarOverlayWindow *overlay = [[ACStatusBarOverlayWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
overlay.hidden = NO;
[overlay makeKeyAndVisible];
}
@implementation StatusBarOverlayWindow
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// Place the window on the correct level and position
self.windowLevel = UIWindowLevelStatusBar + 1;
self.frame = frame;
self.backgroundColor = [UIColor orangeColor];
}
return self;
}
@end
StatusBarOverlayWindow头文件
#import <UIKit/UIKit.h>
@interface StatusBarOverlayWindow : UIWindow {
}
@end
当我点击一个按钮时,什么也没发生。
有人对这个问题有什么想法吗。请引导,谢谢尝试保留对
状态BarOverlay窗口的强引用
,否则在addViewOnTop:
方法完成后,变量将超出范围。这里的房产会很好用的
例如:
@interface ViewController : UIViewController
@property (nonatomic, strong) StatusBarOverlayWindow *overlayWindow;
@end
然后在您的方法中:
- (IBAction)addViewOnTop:(id)sender {
self.overlayWindow = [[ACStatusBarOverlayWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
overlay.hidden = NO;
[overlay makeKeyAndVisible];
}
在调用
makeKeyAndVisible
之前,请尝试保留对当前窗口的StatusBarOverlayWindow
的强引用,并在当前窗口上调用resignKeyWindow
,谢谢我刚才做了强引用,它可以正常工作。但是,关于辞职键窗口
,文档中说不应该直接调用此方法。因此,调用它时我觉得不安全。好的,我添加了这一点作为答案:)请查看我的答案,我想我们只使用overlay.hidden=NO或overlay makeyeandvisible
。