您的位置:首页 > 移动开发 > IOS开发

iOS 横竖屏监听通知

2016-06-28 11:21 429 查看
iOS横竖屏通知有两种,一种监听设备横竖屏状态,另一种监听状态栏横竖屏状态。与布局有关一般使用第二种,因为如果一个viewcontroller不支持自动旋转,当设备由竖屏转横屏时依然会执行监听设备横竖屏的通知方法。

1.监听设备横竖屏

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

- (void)orientChange:(NSNotification *)notification

UIDeviceOrientation  orient = [UIDevice currentDevice].orientation;

4种状态:

UIDeviceOrientationPortrait

UIDeviceOrientationPortraitUpsideDown

UIDeviceOrientationLandscapeLeft

UIDeviceOrientationLandscapeRight

2.监听状态栏横竖屏状态

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientChange:) name:UIApplicationDidChangeStatusBarOrientationNotification object:nil];

- (void)orientChange:(NSNotification *)notification

UIInterfaceOrientation interfaceOritation = [[UIApplication sharedApplication] statusBarOrientation];

4种状态:

UIInterfaceOrientationUnknown            = UIDeviceOrientationUnknown,

UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,

UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,

UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,

UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: