iOS 監聽橫屏豎屏 隱藏狀態列
阿新 • • 發佈:2020-11-21
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]; } }