iOS监听设备方向的方法
2016-06-05 20:54
429 查看
1.添加监听函数
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(deviceOrientationDidChange:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
2.得到设备对象
-(void)deviceOrientationDidChange:(NSObject*)sender{
UIDevice* device = [sender valueForKey:@"object"];
NSLog(@"%d",device.orientation);
}
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(deviceOrientationDidChange:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
2.得到设备对象
-(void)deviceOrientationDidChange:(NSObject*)sender{
UIDevice* device = [sender valueForKey:@"object"];
NSLog(@"%d",device.orientation);
}
相关文章推荐
- ios移动输入框被软键盘遮挡
- IOS 拍照黑屏解决
- IOS开发(转载汇总)
- 文章标题
- iOS中几种常见的查找算法的比较
- CocoaPods 安装和使用
- iOS算法篇(二)选择排序算法
- iOS算法篇(一)快速排序算法
- iOS 简单的runtime替换方法
- iOS动画概述大全
- iOS开发中几种常用设计模式
- iOS coreData使用遇到的问题
- 通过atos命令获取64位错误地址的调用栈
- IOS scrollView与键盘结合使用--防止遮盖控件
- 友盟 crash log 错误分析工具
- iOS 第三方框架-MJExtension的使用
- IOS7笔记-5、视图控制器生命周期
- iOS 第三方框架-Masonry的使用
- iOS_NSNotificationCenter(通知中心)
- iOS 第三方框架-Masonry介绍与使用实践