設(shè)置 Info.plist View controller-based status bar appearance
為YES工秩。
添加4個按鈕云稚,分別控制狀態(tài)欄和導(dǎo)航欄的隱藏和顯示隧饼。
重寫方法 prefersStatusBarHidden
。
//
// SecondViewController.m
// StatusBar
//
// Created by chen.cy on 2021/9/28.
//
#import "SecondViewController.h"
@interface SecondViewController (){
BOOL hiddenStatusBar;
}
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
self.navigationController.navigationBarHidden = YES;
}
- (IBAction)pop:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)hiddenStatusBar:(id)sender {
hiddenStatusBar = YES;
[self setNeedsStatusBarAppearanceUpdate];
}
- (IBAction)showStatusBar:(id)sender {
hiddenStatusBar = NO;
[self setNeedsStatusBarAppearanceUpdate];
}
- (BOOL)prefersStatusBarHidden{
return hiddenStatusBar;
}
- (IBAction)hiddenNavigationBar:(id)sender {
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
- (IBAction)showNavigationBar:(id)sender {
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
@end