扫码关注官方订阅号
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; }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
没地方放压缩包,我就在这里写个简单吧,2个UIViewController,你自己新建一个工程就加两按钮就可以测试。
核心需要添加的方法如下:
1,PortraitViewController 不旋转,保持竖屏
LandscapeViewController 始终保持横屏