1 NSString *statusBarFrame = NSStringFromCGRect([UIApplication sharedApplication].statusBarFrame); 2 NSLog(@"%@", statusBarFrame);
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
UIViewController方法 | 說明 |
- (BOOL)prefersStatusBarHidden NS_AVAILABLE_IOS(7_0); // Defaults to NO | 詢問是否隱藏狀態欄。 |
- (UIStatusBarStyle)preferredStatusBarStyle NS_AVAILABLE_IOS(7_0); // Defaults to UIStatusBarStyleDefault | 詢問狀態欄樣式(UIStatusBarStyleDefault/UIStatusBarStyleLightContent)。 |
// Override to return the type of animation that should be used for status bar changes for this view controller. This currently only affects changes to prefersStatusBarHidden.
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation NS_AVAILABLE_IOS(7_0); // Defaults to UIStatusBarAnimationFade
|
詢問狀態欄顯示或隱藏動畫。 |
// This should be called whenever the return values for the view controller's status bar attributes have changed. If it is called from within an animation block, the changes will be animated along with the rest of the animation block.
- (void)setNeedsStatusBarAppearanceUpdate NS_AVAILABLE_IOS(7_0);
|
設置須要更新狀態欄。主動調用該方法,將間接調用上述三個方法。若是須要動畫生效,需:
[UIView animateWithDuration:0.4
animations:^{ [self setNeedsStatusBarAppearanceUpdate];
}];
|
UIApplication方法/屬性 | 說明 |
// Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.
@property(nonatomic,getter=isStatusBarHidden) BOOL statusBarHidden;
- (void)setStatusBarHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation NS_AVAILABLE_IOS(3_2);
|
設置是否隱藏狀態欄。 |
// Setting statusBarHidden does nothing if your application is using the default UIViewController-based status bar system.
@property(nonatomic) UIStatusBarStyle statusBarStyle; // default is UIStatusBarStyleDefault
- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated;
|
設置狀態欄樣式(UIStatusBarStyleDefault/UIStatusBarStyleLightContent)。 |
@interface ViewController () @property (nonatomic) BOOL statusBarIsHidden; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.statusBarIsHidden = NO; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault; [self performSelector:@selector(setStatusBarHidden:) withObject:@(YES) afterDelay:3.]; [self performSelector:@selector(setStatusBarHidden:) withObject:@(NO) afterDelay:6.]; } - (void)setStatusBarHidden:(BOOL)hidden { self.statusBarIsHidden = hidden; [UIView animateWithDuration:0.4 animations:^{ [self setNeedsStatusBarAppearanceUpdate]; }]; [[UIApplication sharedApplication] setStatusBarHidden:hidden withAnimation:UIStatusBarAnimationSlide]; } - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleDefault; } - (BOOL)prefersStatusBarHidden { return self.statusBarIsHidden; } - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation { return UIStatusBarAnimationSlide; } @end