我在自动布局方向上遇到了问题。简单地说,我正在插入 View Controller 使用这行代码从 rootVC 获取控制权
fooBar *foo = [[fooBar alloc]initWithNibName:@"fooBar" bundle:nil];
[self.navigationController pushViewController:foo animated:NO];
我的 fooBar View Controller 具有自动布局,因此当我转动手机时我应该能够获得横向方向,但手机仍处于纵向模式。
同样奇怪的部分是我调试并且下面的方法不起作用..(我把它们放到 fooBar VC 中)
(BOOL) shouldAutorotate{
return YES;
}
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
//returns true if want to allow orientation change
return TRUE;
}
构建选项 Ios SDK 6.0、Xcode 5.1
最佳答案
这可能是因为导航 Controller 没有转发那些方法调用。如果需要,您需要创建自己的自定义导航 Controller 并遵循以下模式:
- (BOOL)shouldAutorotate
{
return [self.visibleViewController shouldAutorotate];
}
- (NSUInteger)supportedInterfaceOrientations
{
return [self.visibleViewController supportedInterfaceOrientations];
}
总而言之,创建您自己的 UINavigationController 的具体实现,然后将上述两个方法转发到当前可见的任何 View Controller 。然后您应该注意到在您的 fooBar 类中调用了这些方法。
关于ios - 自动布局方向不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24610047/