【发布时间】:2012-06-14 10:36:04
【问题描述】:
我有这段代码(Book1 是 UIViewController 类)
Book1 *book = [self.storyboard instantiateViewControllerWithIdentifier:@"Book1ID"];
[UIView transitionFromView:self.view toView:book.view duration:1 options:UIViewAnimationOptionTransitionCurlDown completion:nil];
ViewController 加载但方向错误。它以纵向视图加载,但我希望它以横向加载。
我已经在 Book1 中有以下代码,但是一旦加载视图,所有自动旋转似乎都失败了。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
return interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight;}
如何在横向中加载此视图?
【问题讨论】:
-
您的故事板设计是否处于横向模式?
-
是的,但我发现我在新实例化的 UIView 上按下的任何按钮都会给我一个错误:消息发送到已释放的实例
-
我修复了释放实例错误,但页面仍然无法在横向视图中打开
-
这就是为什么因为您的整个设计处于纵向模式,并且在加载视图后更改设备方向时将调用方法
-(BOOL)shouldAutorotateToInterfaceOrientation:,因此您必须在横向模式下设计视图才能启动它在风景模式下,或者您必须将您的父/根视图限制为仅风景模式 -
太棒了,如何将其限制为横向?我只在我的设置中选择了横向选项,将我的故事板设置为横向并将应该旋转委托添加到我的类中。
标签: xcode uiview orientation storyboard