iOS 横竖屏监听通知

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值