你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS點擊按鈕隱藏狀態欄詳解及實例代碼

IOS點擊按鈕隱藏狀態欄詳解及實例代碼

編輯:IOS開發綜合

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;
}

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved