iOS在某界面强制横屏

假设前一界面是竖屏,我进入新的viewcontroller,我想让当前界面在初始显示时强制横屏,那要怎么写?跪求指导,跪求千万别百度一下然后回答我,baidu的各种答案我试过,不好用。。。。

阅读 27.9k
4 个回答

自己回答一下,在你需要横屏的viewcontroller中加入,project中的设置要支持landscaperight

- (BOOL) shouldAutorotateToInterfaceOrientation:
            (UIInterfaceOrientation)toInterfaceOrientation {
    return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscapeRight;
}
还有一个问题就是关于转屏是从底部向上的,也就是说,假设当你用navigationcontroller来跳转界面的时候,跳转到的界面的转屏控制与navigationcontroller里的转屏控制是相关的,具体的关联大家自己测试吧

新手上路,请多包涵

我的需求也是竖屏的tabbarcontroller,push到一个横屏的viewcontroller,返回后还是竖屏,只要在这个viewcontroller中加入以下代码就可以了,只在iOS5+测试过

  • (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight); }

  • (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeRight; }

大哥 我用你这个方法没成功啊 打断点不会执行 我需要横屏的界面是push出来的第三层

新手上路,请多包涵
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题