Objective-C屏幕旋转
来源:互联网 发布:sqlserver服务管理器 编辑:程序博客网 时间:2024/06/08 00:12
捕获屏幕旋转
1.注册系统通知:(适用于所有页面)
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeRotate:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
此方法监听的是状态栏的变化,所以系统自动旋转被锁定的时候无法监听的到,常用此方法与系统设置保持一致,还可以监听UIDeviceOrientationDidChangeNotification这个通知,当系统自动旋转呗锁定时依然可以执行,当我们关注的只是物理朝向时,我们通常需要注册该通知来解决问题。
屏幕的旋转朝向可以通过 [[UIDevice currentDevice]orientation] 判断:
- (void)changeRotate:(NSNotification*)notify{ if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortraitUpsideDown) { //竖屏 } else { //横屏 }}
2.willAnimateRotationToInterfaceOrientation:适用于UIViewController,在你的UIViewController中重写该方法:
-( void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) { //竖屏 } else if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) { //横屏 }}
手动调用系统旋转屏幕方法:
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIDeviceOrientationPortrait] forKey:@"orientation"];
上面是旋转到竖屏,可以用UIDeviceOrientationLandscapeLeft或者UIDeviceOrientationLandscapeRight旋转到横屏。
0 0
- Objective-C屏幕旋转
- objective-c 屏幕截图
- Objective-C中的屏幕截图
- 旋转屏幕
- 屏幕旋转
- 屏幕旋转
- 屏幕旋转
- 旋转屏幕
- 屏幕旋转
- 屏幕旋转
- 屏幕旋转
- 屏幕旋转
- 屏幕旋转
- 旋转屏幕
- 屏幕旋转
- 屏幕旋转
- 屏幕旋转
- 屏幕旋转
- 解决PHP数据库乱码问题
- linux之u_boot移植
- iOS 界面 分析工具Reveal
- exec函数族
- java 获取web根目录
- Objective-C屏幕旋转
- Google打算用QUIC协议替代TCP/UDP
- 数据库索引建立原则
- 钱,钱,钱
- 如何使用GreenDAO 3.0
- Mybatis框架
- unity ugui 伤害飘血
- 将Nginx设置为linux下的服务
- Xcode8适配iOS7及以下设备