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
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
相关文章推荐
- iOS 常用公共方法(一)
- iOS开发 Method Swizzling 方法替换
- Quartz2D简单使用(一)
- iOS开发之调用系统应用
- missing ios distribution signing for
- iOS中的谓词(NSPredicate)使用
- Quartz2D简单介绍
- 响应事件传递nextResponder
- iOS 随笔
- Podfile文件详解
- iOS9.0以上tableView reload刷新界面展示问题
- 中文 iOS/Mac 开发博客列表(大
- iOS开发多线程篇 08 —GCD的常见用法
- iOS4 中 Core Motion 框架的介绍和使用
- iOS--错误集锦--svn status 170004
- iOS学习笔记
- iOS知识总结(使用gitbook)
- iOS App中数据管理框架Core Data的基本数据操作教程
- iOS内购流程,从零开始包教包会。
- iOS裁切图片(圆头像的实现)