我试图在视图显示和消失时以编程方式隐藏/取消隐藏状态栏。这是我的第一次尝试(有效),但它激活了我不想发生的UINavigationBar。
-(BOOL)prefersStatusBarHidden
{
return YES;
}
但这基本上是我想要的工作,但它绝对没有。
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
}
-(void)viewWillDisappear:(BOOL)animated
{
[[UIApplication sharedApplication]setStatusBarHidden:NO withAnimation:UIStatusBarAnimationNone];
[super viewWillDisappear:animated];
}
答案 0 :(得分:0)
您应该从
返回setStatusBarHidden:withAnimation:
,而不是UIStatusBarAnimationNone
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
并致电
[self setNeedsStatusBarAppearanceUpdate];
完整代码:
@property(nonatomic,assign,readwrite)BOOL可见;
- (BOOL)prefersStatusBarHidden {
return self.visible;
}
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
return UIStatusBarAnimationNone;
}
- (void)setVisible:(BOOL)visible {
_visible = visible;
[self setNeedsStatusBarAppearanceUpdate];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.visible = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
self.visible = NO;
[super viewWillDisappear:animated];
}
答案 1 :(得分:0)
只需添加一个简单的行,您的问题就会解决。
[[UIApplication sharedApplication] setStatusBarHidden:status];