ios - 自动布局方向不起作用

标签 ios rotation orientation autolayout portrait

我在自动布局方向上遇到了问题。简单地说,我正在插入 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/

相关文章:

iphone - 为什么游戏开发者要将许多图像放入一张大图像中?

ios - 如何避免旋转过程中的约束冲突?

c++ - 现代 OpenGL 立方体旋转无法按预期工作

java - 游戏对象旋转形成椭圆形而不是圆形

ios - 在纵向/横向旋转中旋转除 UIImageView 之外的所有内容

iphone - 埃塞俄比亚 unicode 在 iPhone 模拟器上显示为方框

objective-c - UIFont fontWithName 返回 nil

ios - 如何将配置文件上传到 iPhone

android - 如何在android上制作准确的指南针

javascript - iPad 上的 Safari 在纵向模式下不适合 980px 宽度的网站