iOS指定页面旋转

今天下午遇到一个需求,在原有只支持竖屏的应用上需要一个页面支持横屏。琢磨了一会,最后是这样解决的:

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"];

这样就解决了这个问题。



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值