关于ios:iOS-监听横屏竖屏-隐藏状态栏

BOOL _isFullScreen;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rotated:) name:UIDeviceOrientationDidChangeNotification object:nil];

- (void)rotated:(NSNotification *)notification
{
    UIDevice *dv = notification.object;
    /*
     
     UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight
     */
    if (dv.orientation == UIDeviceOrientationLandscapeLeft ||
        dv.orientation == UIDeviceOrientationLandscapeRight)
    {
        NSLog(@"横屏");
        _isFullScreen = true;
  
    }else if (dv.orientation == UIDeviceOrientationFaceUp ||
         dv.orientation == UIDeviceOrientationFaceDown)
     {
         NSLog(@"face");
     }else{
         NSLog(@"竖屏");
         _isFullScreen = NO;
    }
    [self reloadStatuestBar];
}
- (BOOL)prefersStatusBarHidden
{
    return _isFullScreen;
}
- (void)reloadStatuestBar {
    if ( [self  respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)] ) {
        // go prefersStatusBarHidden
         [self setNeedsStatusBarAppearanceUpdate];
    } else {
        [[UIApplication sharedApplication] setStatusBarHidden:_isFullScreen];
    }
}

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理