隐藏Status bar,隐藏状态栏的正确姿势

//隐藏状态栏方法
- (IBAction)hideStatus:(id)sender {
    self.ishide = YES;
    // [self setNeedsStatusBarAppearanceUpdate]需要放在animation block内才能生效
    [UIView animateWithDuration:1 animations:^{
        [self setNeedsStatusBarAppearanceUpdate];
    }];
}

//显示状态栏方法
- (IBAction)showStatus:(id)sender {
    self.ishide = NO;
    [UIView animateWithDuration:1 animations:^{
        [self setNeedsStatusBarAppearanceUpdate];
    }];
}

//重写preferredStatusBarStyle 设置状态栏颜色
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleDefault;
}

//重写prefersStatusBarHidden 设置状态栏是否隐藏
-(BOOL)prefersStatusBarHidden
{
    return self.ishide;
}
//重写preferredStatusBarUpdateAnimation 设置状态栏动画
-(UIStatusBarAnimation)preferredStatusBarUpdateAnimation
{
    return UIStatusBarAnimationSlide;
}

你可能感兴趣的:(隐藏Status bar,隐藏状态栏的正确姿势)