检测手机屏幕的旋转
来源:互联网 发布:沙迪克慢走丝编程 编辑:程序博客网 时间:2024/04/28 18:24
在特别的场景下,需要针对屏幕旋转作特殊处理。在ios系统下实现相关的功能还是比较方便的。
我下面介绍两种方法:
1.注册UIApplicationDidChangeStatusBarOrientationNotification通知(举例:在一个viewcontroller类的viewdidload中注册该通知),示例代码如下:
[[NSNotificationCenterdefaultCenter] addObserver:selfselector:@selector(statusBarOrientationChange:)name:UIApplicationDidChangeStatusBarOrientationNotificationobject:nil];
- (void)statusBarOrientationChange:(NSNotification *)notification
{
UIInterfaceOrientation orientation = [[UIApplicationsharedApplication] statusBarOrientation];
if (orientation ==UIInterfaceOrientationLandscapeRight) // home键靠右
{
//
}
if (
orientation ==UIInterfaceOrientationLandscapeLeft)// home键靠左
{
//
}
if (orientation ==UIInterfaceOrientationPortrait)
{
//
}
if (orientation ==UIInterfaceOrientationPortraitUpsideDown)
{
//
}
}
注意这种方式监听的是StatusBar也就是状态栏的方向,所以这个是跟你的布局有关的,你的布局转了,才会接到这个通知,而不是设备旋转的通知。当我们关注的东西和布局相关而不是纯粹设备旋转,我们使用上面的代码作为实现方案比较适合。
2.注册UIDeviceOrientationDidChangeNotification通知(举例:我们同样在一个viewcontroller类的viewdidload中注册该通知),示例代码如下:
[[NSNotificationCenter defaultCenter] addObserver:selfselector:@selector(orientChange:)name:UIDeviceOrientationDidChangeNotificationobject:nil];
- (void)orientChange:(NSNotification *)noti
{
NSDictionary* ntfDict = [noti userInfo];
UIDeviceOrientation orient = [UIDevicecurrentDevice].orientation;
/*
UIDeviceOrientationUnknown,
UIDeviceOrientationPortrait, // Device oriented vertically, home button on the bottom
UIDeviceOrientationPortraitUpsideDown, // Device oriented vertically, home button on the top
UIDeviceOrientationLandscapeLeft, // Device oriented horizontally, home button on the right
UIDeviceOrientationLandscapeRight, // Device oriented horizontally, home button on the left
UIDeviceOrientationFaceUp, // Device oriented flat, face up
UIDeviceOrientationFaceDown // Device oriented flat, face down */
switch (orient)
{
caseUIDeviceOrientationPortrait:
break;
caseUIDeviceOrientationLandscapeLeft:
break;
caseUIDeviceOrientationPortraitUpsideDown:
break;
caseUIDeviceOrientationLandscapeRight:
break;
default:
break;
}
}
注意到这种方式里面的方向还包括朝上或者朝下,很容易看出这个完全是根据设备自身的物理方向得来的,当我们关注的只是物理朝向时,我们通常需要注册该通知来解决问题(另外还有一个加速计的api,可以实现类似的功能,该api较底层,在上面两个方法能够解决问题的情况下建议不要用,使用不当性能损耗非常大)。- 检测手机屏幕的旋转
- 手机屏幕旋转180度
- 判断手机屏幕旋转方向
- IOS - 判断手机屏幕旋转
- 判断手机屏幕是否旋转
- 旋转人脸的检测及检索
- 圆与旋转矩形的碰撞检测
- 屏幕旋转--自动及手动控制(视频播放中setRequestedOrientation之后手机屏幕的旋转不触发onConfigurationChanged方法)
- Android 解决setRequestedOrientation之后手机屏幕的旋转不触发onConfigurationChanged方法
- Android 解决setRequestedOrientation之后手机屏幕的旋转不触发onConfigurationChanged方法
- Android 解决setRequestedOrientation之后手机屏幕的旋转不触发onConfigurationChanged方法
- Android 解决setRequestedOrientation之后手机屏幕的旋转不触发onConfigurationChanged方法
- Android 解决setRequestedOrientation之后手机屏幕的旋转不触发onConfigurationChanged方法
- Android 解决setRequestedOrientation之后手机屏幕的旋转不触发onConfigurationChanged方法
- Android 解决setRequestedOrientation之后手机屏幕的旋转不触发onConfigurationChanged方法
- android获取手机屏幕尺寸和旋转方向
- android 手机屏幕旋转机制与使用说明
- iOS开发如何禁止手机屏幕旋转
- Address already in use的解决方法
- [iOS]UIView动画学习笔记(上)
- Openfire 性能优化
- python的server和client的简单建立
- 关于反射类型的名词解释
- 检测手机屏幕的旋转
- java多态性的体现
- 统治世界的十大算法
- python 页面信息抓取
- Android 监控内存泄漏的开源代码
- linux 全盘搜索
- python模块下载安装
- 利用pip 安装相同python包环境
- CG 数据类型