ios中可以设置是横屏还是竖屏。但如果你在xcode中同时选择了横屏和竖屏,当你旋转屏幕时,你的view就会同时就会跟着旋转。我现在的问题时,我的app要有两个view,一个是支持横屏的,但它不能选择,永远横屏。另外一个是竖屏的,永远是竖屏的,也不能再选择。两个view通过一个button关联,点一下,进入另一个。
解决方案
没地方放压缩包,我就在这里写个简单吧,2个UIViewController,你自己新建一个工程就加两按钮就可以测试。
核心需要添加的方法如下:
1,PortraitViewController 不旋转,保持竖屏
//iOS 5- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ return (toInterfaceOrientation == UIInterfaceOrientationPortrait);}//iOS 6- (BOOL)shouldAutorotate{ return NO;}- (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskPortrait;}- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ return UIInterfaceOrientationPortrait;}
LandscapeViewController 始终保持横屏
//iOS 5- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ return (toInterfaceOrientation == self.preferredInterfaceOrientationForPresentation);}//iOS 6- (BOOL) shouldAutorotate{ return YES;}- (NSUInteger)supportedInterfaceOrientations{ return UIInterfaceOrientationMaskLandscapeRight;}- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ return UIInterfaceOrientationLandscapeRight;}