IOS6 屏幕旋转 以及 旋转后的对应方法
来源:互联网 发布:仲元中学知乎 编辑:程序博客网 时间:2024/05/06 15:28
想要在IOS6下支持屏幕旋转,首先有一下两点要求:
1、在 Info.plist 中需要有Supported interface orientations支持(默认支持三个方向的旋转)
2、 在添加页面是,采取的是ViewController形式,而不是view
例如: AppDelegate中,[self.windows setRootViewController viewController ]
而不是: [self.windows.view addSubview: viewController.view]
接下来就可以设置屏幕支持了,ios默认只支持竖屏,不支持转屛
1、在viewControll.m 文件中添加函数,表明支持旋转屏幕
- (BOOL)shouldAutorotate{ return YES;}这个函数的意思是,是否支持旋转屏幕,YES ,支持
2、 添加函数,表明支持具体哪几个屏幕
- (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskAll;}return的就是支持屏幕的类型,在IOS6之前,一般是返回UIInterfaceOrientation 类型,上次左右,简单明了
typedef NS_ENUM(NSInteger, UIInterfaceOrientation) { UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight, UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft};
但是IOS6定义了新的类型UIInterfaceOrientationMask,定义如下:
typedef NS_OPTIONS(NSUInteger, UIInterfaceOrientationMask) { UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait), UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft), UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight), UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown), UIInterfaceOrientationMaskLandscape = (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight), UIInterfaceOrientationMaskAll = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown), UIInterfaceOrientationMaskAllButUpsideDown = (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),};这个类型,不仅包括上下左右,还包括他们的不同合集,比如左右,上下左右,上左右等,我在函数中的返回值 UIInterfaceOrientationMaskAll 就是指,所有的旋转都支持
如此,旋转的设置便定义好了。
那么,如何准对旋转,来执行相应的方法呢?
我们便需要用到
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration在函数里,可以根据对应的UIInterfaceOrientation 来应对,举例如下:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{ if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) { NSLog(@"left"); self.view.backgroundColor = [UIColor greenColor]; } if (toInterfaceOrientation == UIInterfaceOrientationPortrait) { self.view.backgroundColor = [UIColor whiteColor]; NSLog(@"center"); } if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { self.view.backgroundColor = [UIColor yellowColor]; NSLog(@"right"); } }
这个Demo就是根据屏幕的旋转来变换不同的色,很简单,不解释。
源代码如下:屏幕旋转源代码
0 0
- IOS6 屏幕旋转 以及 旋转后的对应方法
- iOS6屏幕旋转
- iOS6屏幕旋转
- IOS6屏幕旋转
- ios6 屏幕旋转总结
- iOS6屏幕旋转
- IOS6屏幕旋转问题
- 关于IOS6屏幕旋转
- ios6 屏幕旋转问题
- ios6 屏幕旋转
- IOS6屏幕旋转详解
- IOS6屏幕旋转详解
- ios6 屏幕旋转总结
- iOS6下关于屏幕旋转的控制
- 关于iOS6.0 屏幕旋转的问题
- iOS6的控制屏幕旋转技巧
- iOS6下关于屏幕旋转的控
- iOS6的控制屏幕旋转技巧
- fedora/linux yum源详细设置(强烈推荐)
- hibernate常见问题
- Flappy Bird
- 第十八讲:多态
- 黑马程序员---面对对象之接口的定义和使用
- IOS6 屏幕旋转 以及 旋转后的对应方法
- Game of Wuxing
- samba的配置
- Hydra与Hadoop之争谁将胜利?
- 策略路由和NAT实现负载均衡实例教程
- 模糊控制部分函数用法
- redhat server 5.6安装nmon
- 移动tomcat之后总共需要修改的三个地方
- Bing"以图搜图"晚谷歌30个月