2

我在导航控制器中有一个 UIView,我试图阻止这个视图进入景观,但是我尝试使用的方法永远不会触发..代码低于任何帮助将不胜感激..

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        return NO;
    }
    else if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
        return NO;
    }
    return NO;
}
4

3 回答 3

4

您应该return NO;为父导航控制器或在 a 上设置UIViewController,而不是在UIView.

此外,这与更少的代码相同:

iOS 5.x

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

iOS 6

从 iOS 6 开始,shouldAutorotateToInterfaceOrientation:已弃用。如果视图控制器不覆盖该supportedInterfaceOrientations方法,UIKit则从应用程序委托或应用程序的 Info.plist 文件中获取默认旋转。

您将需要使用:

- (NSUInteger)supportedInterfaceOrientations NS_AVAILABLE_IOS(6_0);
于 2012-07-11T21:33:16.443 回答
1

另一种选择是修改部署信息。

截屏

于 2014-09-10T23:29:07.583 回答
0

此方法需要在UIViewController实例中实现,而不是在UIView.

此外,您实际上正在返回NO所有方向,这是不正确的。您需要返回YES至少一个方向(最常见的方向UIInterfaceOrientationPortrait)。

于 2012-07-11T21:33:24.643 回答