我希望这个模态视图以横向模式显示,但我不能让它自动转动.
我在模态视图控制器中有这个
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); }
我已将landscapeLeft添加到.plist支持的方向(虽然这也允许TabBar旋转,我不想要)
我还将它添加到模态视图的ViewDidLoad中
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;
但我不能让它自己旋转.
谢谢
编辑—-
似乎应该甚至没有调用自动旋转!
此外,我正在尝试检测方向,下面的代码总是显示2,无论方向如何!
if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait) { NSLog(@"1"); self.hostView.frame = CGRectMake(0,60,200,255); } else { NSLog(@"2"); self.hostView.frame = CGRectMake(0,45,480,255); }
编辑2 —
我的错.我想我应该提到我正在使用iOS 6.显示器在iOS 5上自动旋转.
shouldAutorotateToInterfaceOrientation已弃用,因此我需要阅读新方法.
解决方法
iOS 6.0 Release Notes
“More responsibility is moving to the app and the app delegate. Now,iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate. “
– (BOOL)不应该从IOS6调用任何Container(如UINavigationController)下的UIViewController的Uutorotate.
尝试使用Category将方法添加到现有UINavigationController类的解决方案.
在shouldAutorotate方法中,您可以在self.viewControllers的每个视图控制器中调用shouldAutorotate方法.实际上,您可以传递给您的子视图控制器.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。