iOS 控制单个控制器旋转
2023-09-11 14:15:06 时间
iOS 控制单个控制器旋转
控制单个ViewController 的旋转
//不旋转,保持竖屏 //iOS 5 - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return (toInterfaceOrientation == UIInterfaceOrientationPortrait); } //iOS 6 - (BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationPortrait; } //始终保持横屏 //iOS 5 - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return (toInterfaceOrientation == self.preferredInterfaceOrientationForPresentation); } //iOS 6 - (BOOL) shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeRight; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return UIInterfaceOrientationLandscapeRight; }
然而上面的代码在有 导航条的情况下,并不好用;解决方式,为导航条UINavigationController 创建一个 分类,并使用如下分类的导航条
@implementation UINavigationController (Rotation) -(BOOL)shouldAutorotate { return [[self.viewControllers lastObject] shouldAutorotate]; } -(NSUInteger)supportedInterfaceOrientations { return [[self.viewControllers lastObject] supportedInterfaceOrientations]; } - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; } @end
参考 http://blog.csdn.net/wudizhukk/article/details/8674393
相关文章
- iOS 9音频应用播放音频之控制播放速度
- iOS 9音频应用播放音频之播放控制暂停停止前进后退的设置
- iOS Sprite Kit教程之滚动场景
- IOS开发资料汇总
- iOS UIView视图的图层控制
- Hello_IOS ios开发transform属性
- iOS之基于FreeStreamer的简单音乐播放器(模仿QQ音乐)
- ios GUI系统综述:iOS的图形绘制、动画与runloop
- iOS开发笔记--关于 @synchronized,这儿比你想知道的还要多
- iOS 一些常见问题的整理
- iOS 内存使用陷阱
- IOS_ios逆向工程-静态分析
- IOS开发邓白氏编码申请教程
- weex-platform里iOS项目打包报错/platforms/ios/../../start does not exist.
- iOS-横竖屏管理,支持所有方向旋转时用代码控制允许旋转&不允许旋转