iOS屏幕旋转
2017-12-13 11:39
585 查看
1. 总开关在工程设置,General-Deployment Info-Device Orientation下勾选工程需要的选项。如果程序中所有的页面不会用到横屏,则只需要勾选Portrait。如果工程中部分页面需要横屏,则需要勾选竖屏和横屏的选项。
2. 在AppDelegate中设置旋转页面:
在AppDelegate.h文件中添加一个Flag,用来设置App全局是否可以横屏。
在AppDelegate.m文件中设置App的旋转代理方法。
3. 单个的页面是否可以旋转,需要在代理方法中设置
4. ViewController嵌套在UINavigationController中,如果ViewController需要横屏展示,此时需要设置UINavigationController的选装代理方法。
这里提供一个自定义的UINavigationController的实现类:
CustomNavViewController.h
CustomNavViewController.m
5. ViewController嵌套在UITabBarController中,需要设置UITabBarController的旋转方向.
这里提供一个自定义的UITabBarController的类:
CustomTabBarController.h
CustomTabBarController.m
2. 在AppDelegate中设置旋转页面:
在AppDelegate.h文件中添加一个Flag,用来设置App全局是否可以横屏。
@property (nonatomic, assign) BOOL isPotrait; //设置整个App是否可以旋转
在AppDelegate.m文件中设置App的旋转代理方法。
#pragma mark-屏幕旋转相关的方法 - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{ if (self.isPotrait) { return UIInterfaceOrientationMaskPortrait; }else{ return UIInterfaceOrientationMaskAllButUpsideDown; } }
3. 单个的页面是否可以旋转,需要在代理方法中设置
#pragma mark-支持旋转的代理 - (BOOL)shouldAutorotate{ return YES; } - (UIInterfaceOrientationMask)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskAllButUpsideDown; }
4. ViewController嵌套在UINavigationController中,如果ViewController需要横屏展示,此时需要设置UINavigationController的选装代理方法。
这里提供一个自定义的UINavigationController的实现类:
CustomNavViewController.h
#import <UIKit/UIKit.h> @interface CustomNavViewController : UINavigationController @end
CustomNavViewController.m
#import "CustomNavViewController.h" @interface CustomNavViewController () @end @implementation CustomNavViewController - (void)viewDidLoad { [super viewDidLoad]; self.navigationBar.hidden = YES; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark-控制页面旋转的方法 - (BOOL)shouldAutorotate{ return self.topViewController.shouldAutorotate; } - (UIInterfaceOrientationMask)supportedInterfaceOrientations{ return self.topViewController.supportedInterfaceOrientations; } @end
5. ViewController嵌套在UITabBarController中,需要设置UITabBarController的旋转方向.
这里提供一个自定义的UITabBarController的类:
CustomTabBarController.h
#import <UIKit/UIKit.h> @interface CustomTabBarController : UITabBarController @end
CustomTabBarController.m
#import "CustomTabBarController.h" #import "CustomNavViewController.h" @interface CustomTabBarController () @end @implementation CustomTabBarController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } #pragma mark-控制旋转的代理方法 - (BOOL)shouldAutorotate{ CustomNavViewController *nav = (CustomNavViewController *)[self.viewControllers objectAtIndex:self.selectedIndex]; return nav.topViewController.shouldAutorotate; } - (UIInterfaceOrientationMask)supportedInterfaceOrientations{ CustomNavViewController *nav = (CustomNavViewController *)[self.viewControllers objectAtIndex:self.selectedIndex]; return nav.topViewController.supportedInterfaceOrientations; } @end
相关文章推荐
- iOS指定页面屏幕旋转,手动旋转(某app实现功能全过程)
- ios屏幕旋转的两种实现方式
- 关于IOS屏幕的旋转问题
- iOS屏幕旋转详解
- 【转】IOS屏幕旋转与View的transform属性之间的关系,比较底层
- ios 关于屏幕旋转和屏幕晃动
- ios开发 旋转屏幕supportedInterfaceOrientationsForWindow函数概要
- 转载 -- IOS成长之路-关于iOS6.0 屏幕旋转的问题
- ios(ipad,iphone)屏幕旋转检测通用方法
- iOS屏幕横竖屏旋转相关
- IOS UIDevice & IOS检测屏幕旋转实例
- iOS屏幕旋转
- 【转载】iOS开发之屏幕旋转
- iOS Orientation 屏幕旋转
- iOS屏幕旋转学习笔记
- IOS屏幕旋转详解(自动旋转、手动旋转、兼容IOS6之前系统)
- ios屏幕旋转注意事项
- iOS 屏幕旋转常用方式
- IOS 6下设置屏幕旋转方向代码
- 关于IOS屏幕的旋转问题