检测手机的屏幕方向
来源:互联网 发布:mysql ibtmp1 删除 编辑:程序博客网 时间:2024/04/29 02:18
检测手机的屏幕方向:
一、在需要检测的页面里的ViewDidLoad方法里注册通知:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleDeviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
二、检测设备方向的回调方法
- (void)handleDeviceOrientationDidChange: (UIInterfaceOrientation)interfaceOrientation {
UIDevice *device = [UIDevice currentDevice];
switch (device.orientation) {
case UIDeviceOrientationFaceUp:
NSLog(@"屏幕朝上平躺");
break;
case UIDeviceOrientationFaceDown:
NSLog(@"屏幕朝下平躺");
break;
case UIDeviceOrientationUnknown:
NSLog(@"未知方向");
break;
case UIDeviceOrientationLandscapeLeft: {
NSLog(@"屏幕向左横置");
}
break;
case UIDeviceOrientationLandscapeRight:
NSLog(@"屏幕向右橫置");
break;
case UIDeviceOrientationPortrait: {
NSLog(@"屏幕直立");
}
break;
case UIDeviceOrientationPortraitUpsideDown:
NSLog(@"屏幕直立,上下顛倒");
break;
default:
NSLog(@"无法辨识");
break;
}
}
三、注销 Device
- (void)dealloc{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[UIDevice currentDevice]endGeneratingDeviceOrientationNotifications];
}
- 检测手机的屏幕方向
- 【Android 开发教程】检测屏幕的方向
- Android检测当前屏幕的方向
- iOS_关于手机支持的屏幕方向
- iOS_关于手机支持的屏幕方向
- 传感器--------屏幕方向检测
- Android 手机改变屏幕方向
- Android获取手机分辨率 和屏幕的方向
- 获取手机的默认屏幕方向——某些平板的方向错误问题
- 设置屏幕的方向
- js判断手机浏览器屏幕方向
- 检测 Tablet PC 应用程序中的屏幕方向和屏幕旋转
- js/css 检测移动设备方向的变化 判断横竖屏幕
- iOS中检测当前设备的旋转方向(关闭屏幕旋转)
- 关于手机启动的方向,和屏幕的单,双击事件
- 从Ubuntu Screen API得到屏幕信息及手机的方向信息
- android 获取屏幕的方向
- 获得当前的屏幕方向
- AngularJS控制器
- Webpack模块解析
- json解析大全,双引号,键值对不在一起的情况
- PHP_notes_06
- Java迭代器(转)(iterator详解以及和for循环的区别)
- 检测手机的屏幕方向
- 修复VBS病毒感染的html文件
- EventBus黏性事件(简单的登录传值)
- java 网络流 TCP Socket和SeverSocket 上传文件(字节流)+ 服务器多线程
- 浅谈Java web 中request的setAttribute()用法
- PHP_分析购物车
- log4j警告后,程序停顿不继续运行
- numpy tips one
- R