首页 文章

界面方向不会自动更改

提问于
浏览
-1

我无法在通用应用中更改界面方向 . 它有一个导航控制器 . 我已将视图控制器添加到导航控制器,并将导航控制器的视图添加到窗口 . 如果我删除导航控制器并将视图控制器的视图作为子视图添加到窗口,则它会识别方向,但如果我添加导航控制器的视图,则界面方向不会更改 . 请帮我一些参考 . 以下是我的代码 . - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

if ([self.view isKindOfClass:[UINavigationController class]]) {
     UIViewController *rootController = [((UINavigationController*)self.view).viewControllers objectAtIndex:0];
        return [rootController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    }
return YES;

}

1 回答

  • 2

    请务必覆盖 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 方法 . 默认情况下,UIViewController仅为纵向模式返回yes .

相关问题