@interface SecondViewController ()
@property (nonatomic, assign,getter=isHideStatus) BOOL hideStatus;
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];
button.center = self.view.center;
button.backgroundColor = [UIColor blueColor];
[button setTitle:@"隐藏導航欄" forState:UIControlStateNormal];
[button addTarget:self action:@selector(hideFrame) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
self.hideStatus = [UIApplication sharedApplication].statusBarHidden;
// Do any additional setup after loading the view, typically from a nib.
}
- (void)hideFrame {
[self setNeedsStatusBarAppearanceUpdate];//調用該方法後系統會調用prefersStatusBarHidden方法
self.hideStatus = !self.hideStatus;
}
- (BOOL)prefersStatusBarHidden
{
return self.hideStatus;
}