如何在UINavigationController rootViewController上禁用纵向方向

Sha*_*a G 1 iphone objective-c orientation uinavigationcontroller

我有一个类HomeView,作为我的iPad应用程序上的UINavigationController的rootViewController.仅在info.plist文件中设置了横向方向,并且HomeView未实现shouldRotateToInterfaceOrientation:,但是在模拟器旋转时视图正在为两个方向旋转.

我如何仅在UIViewController中使用横向方向?

Tho*_*din 5

如果你没有实现shouldAutorotateToInterfaceOrientation:运行时将调用Super类UIViewController上的方法.

相反,您应该使用要旋转的方向适当地响应方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    BOOL shouldAutorotate = NO;

    if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft
        || interfaceOrientation == UIInterfaceOrientationLandscapeRight) {

        shouldAutorotate = YES;
    }

    return shouldAutorotate;
}
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请查看UIInterfaceOrientation参考页面和UIViewController的shouldAutorotateToInterfaceOrientation:参考页面.