昨天朋友问我,怎么实如今竖屏的应用里,显示一个横屏的应用,因为也没作过测试
就说不知道了,可是我以为会有这样的API ,由于我手机里就安装有这种类型的软件spa
今天早上起来,就想作一个Demo出来,惯例的是查找资料,测试是否可使用,可是code
查找了都写的不是很清楚,很容易形成无法实现想要的效果,因此想从新写过一个blog
但愿能帮到有这个需求的朋友。(这个没什么经验,的是照着网上的资料拼凑起来,it
若是有错误,请见谅,有更好的办法也能够告诉我)io
实现的效果:ast
页面大部分是竖屏,个别页面能够旋转手机时页面变为横屏(其实朋友的需求是,进入class
这个页面就是横屏的,不知道怎么弄)。软件
实现步骤:方法
1.使应用能够横屏,新建立的默认就能够
2.在跟视图里实现如下的方法(导航控制器和TabBar控制器的能够)
-(BOOL)shouldAutorotate { return YES; } -(NSUInteger)supportedInterfaceOrientations { return [self.viewControllers.lastObject supportedInterfaceOrientations]; } -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation]; }
3.在不须要横屏的视图控制器里面实现如下方法
-(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait ; } - (BOOL)shouldAutorotate { return NO; } -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait; }
4,须要横屏的页面不须要其余的处理就能够了。