1、屏幕扭转时,建议监听UIApplicationDidChangeStatusBarOrientationNotification
4) 在QSTabBarController设置
目标:TabBarController平日作为全部法度榜样的rootViewController,UITabBar膳绫擎显示的每一个Tab都对应着一个ViewController;每点击一个Tab,出现的ViewController(self.selectedViewController)对屏幕扭转和支撑偏向的设置 交给其自身去控制。
- //QSTabBarController.h
- @interface QSTabBarController : UITabBarController
- @end
- //QSTabBarController.m
- @implementation QSTabBarController
- #pragma mark - 控制屏幕扭转办法
- - (BOOL)shouldAutorotate{
- return [self.selectedViewController shouldAutorotate];
- }
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations{
- return [self.selectedViewController supportedInterfaceOrientations];
- }
- - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
- return [self.selectedViewController preferredInterfaceOrientationForPresentation];
- }
- @end
三、屏幕扭转偏向下的视图处理
原因1:supportedInterfaceOrientations办法中最终返回的是 多个界面偏向。
原因2(最重要的原因):我们真正要处理的是页面偏向产生扭转UI的变更。而在设备的物理偏向产生扭转的时刻,如不雅此时当前控制器的页面并没有扭转,我们这时改变UI构造,可能就产生问题了。
2、屏幕的宽高处理
1)在iOS 8之后,当屏幕扭转的时刻,[[UIScreen mainScreen] bounds]也产生了改变。如横屏时刻的屏幕宽度 其实是竖屏的时刻屏幕的高度。
2)我们处理视图构造时刻,如不雅应用到屏幕的宽高,不要直接应用SCREEN_HEIGHT和SCREEN_WIDTH,而应用SCREEN_MIN和SCREEN_MAX
- #define SCREEN_HEIGHT CGRectGetHeight([[UIScreen mainScreen] bounds])
- #define SCREEN_WIDTH CGRectGetWidth([[UIScreen mainScreen] bounds])
- #define SCREEN_MIN MIN(SCREEN_HEIGHT,SCREEN_WIDTH)
推荐阅读
近年来,Python 在数据科学行业扮演着越来越重要的角色。是以,我根据比来的应用体验,在本文中列出了对数据科学家、工程师们最有效的那些库。因为这些库都开源了,我们大年夜Github上惹人>>>详细阅读
本文标题:代码处理iOS的横竖屏旋转
地址:http://www.17bianji.com/lsqh/36388.html
1/2 1