iOS指定页面旋转
2016-01-13 16:02
447 查看
今天下午遇到一个需求,在原有只支持竖屏的应用上需要一个页面支持横屏。琢磨了一会,最后是这样解决的:
1. 在general页面勾选支持横屏的两个选项,并勾选requires full screen选项,让应用支持横屏显示。
2. 自定义一个导航控制器CustomerViewController:UINavigationController,实现如下方法:
- (BOOL)shouldAutorotate
{
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
if ([self.topViewController isKindOfClass:[DetailQuotaController class]])
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
return UIInterfaceOrientationMaskPortrait;
}
3. 在根视图控制器中,添加如下方法:
- (BOOL)shouldAutorotate
{
UIViewController * navVC = self.selectedViewController;
if ([navVC isKindOfClass:[CustomerViewController class]])
{
return YES;
}
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
UIViewController * vc = self.selectedViewController;
if (vc)
{
return [vc supportedInterfaceOrientations];
}
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
UIViewController * vc = self.selectedViewController;
if (vc)
{
return [vc preferredInterfaceOrientationForPresentation];
}
return UIInterfaceOrientationPortrait;
}
这样就可以实现了。
但是这样从横屏界面pop到上一个界面是存在一点问题的,所以还是需要再做一个设置,
在其pop回去的那个页面里加上两行代码:
NSNumber * number = [NSNumber numberWithInt:UIInterfaceOrientationMaskPortrait];
[[UIDevice currentDevice] setValue:number forKey:@"orientation"];
这样就解决了这个问题。
1. 在general页面勾选支持横屏的两个选项,并勾选requires full screen选项,让应用支持横屏显示。
2. 自定义一个导航控制器CustomerViewController:UINavigationController,实现如下方法:
- (BOOL)shouldAutorotate
{
return YES;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
if ([self.topViewController isKindOfClass:[DetailQuotaController class]])
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
return UIInterfaceOrientationMaskPortrait;
}
3. 在根视图控制器中,添加如下方法:
- (BOOL)shouldAutorotate
{
UIViewController * navVC = self.selectedViewController;
if ([navVC isKindOfClass:[CustomerViewController class]])
{
return YES;
}
return NO;
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
{
UIViewController * vc = self.selectedViewController;
if (vc)
{
return [vc supportedInterfaceOrientations];
}
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
UIViewController * vc = self.selectedViewController;
if (vc)
{
return [vc preferredInterfaceOrientationForPresentation];
}
return UIInterfaceOrientationPortrait;
}
这样就可以实现了。
但是这样从横屏界面pop到上一个界面是存在一点问题的,所以还是需要再做一个设置,
在其pop回去的那个页面里加上两行代码:
NSNumber * number = [NSNumber numberWithInt:UIInterfaceOrientationMaskPortrait];
[[UIDevice currentDevice] setValue:number forKey:@"orientation"];
这样就解决了这个问题。
相关文章推荐
- 设置cell间距
- IOS集成到支付宝的步骤及问题
- iOS Developer Program开发者证书的区别
- iOS 图文混排 链接 可点击
- iOS开发笔记--基于面向协议MVP模式下的软件设计
- iOS 字体加粗
- Git忽略规则及.gitignore规则不生效的解决办法
- 【学习总结】iOS中NSNotification、delegate、KVO三者之间的区别与联系?
- iOS(五)基于XMPP的聊天:一
- iOS开发多线程篇—GCD介绍
- 华为服务器RH5885 V3进入BIOS
- iOS个人整理08-touch触摸事件和手势识别器
- iOS-OC复合语句
- iOS开发教程之线程关于多线程的简单介绍
- cannot do a partial commit during a merge.
- IOS应用开发版本控制工具之Versions 和SVN 的 使用方法详解
- iOS项目的完整重命名方法图文教程
- iOS下载图片之SDWebImage的研究与使用
- iOS类似支付宝首页Item项的移动排序
- 录制视频的大Bug (IOS 不能播放)