IOS點擊按鈕隱藏狀態欄詳解
前言:
最近學習IOS的基礎知識,實現隱藏狀態欄的功能,這里就記錄下來,希望對大家有所幫助
實例代碼:
@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(0, 0, 300, 200)]; 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;}
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答