【问题标题】:unable to rotate only one view无法仅旋转一个视图
【发布时间】:2012-01-23 21:15:14
【问题描述】:

我正在使用 XCode 4.2(带有情节提要)

我正在尝试仅旋转其中一个视图(而不是所有视图),但它似乎不起作用......要么没有视图旋转,要么全部旋转

我已经检查了摘要中所有支持的视图,并且在信息中我确保应用程序“支持的界面方向”都在那里

在与视图相关的类中,我编写了旋转该特定视图的函数:

-(BOOL) shouldAutoRotateToInterfactOrientation:(UIInterfaceOrientation)interfaceOrientation{
return(interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown||
interfaceOrientation != UIInterfaceOrientationPortrait||
interfaceOrientation != UIInterfaceOrientationLandscapeRight||
interfaceOrientation != UIInterfaceOrientationLandscapeLeft)
}

当我旋转屏幕时它仍然不旋转......有什么线索吗?

【问题讨论】:

  • 你确定那些“不相等”的运算符吗?你不应该使用“==”还是直接返回YES?
  • 我尝试了“是”并尝试了 ==... 没有工作

标签: iphone objective-c ios xcode4.2 storyboard


【解决方案1】:

您的方法可以简化为:

- (BOOL)shouldAutoRotateToInterfactOrientation:(UIInterfaceOrientation)interfaceOrientation; {
  return YES;
}

您要做的是让设备支持您想要的所有方向,然后在特定视图中,使用上述方法允许该视图所需的方向。因此,例如,如果您只想要特定视图的横向模式,您可以使用:

- (BOOL)shouldAutoRotateToInterfactOrientation:(UIInterfaceOrientation)interfaceOrientation; {
  return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

希望有帮助!

【讨论】:

    【解决方案2】:

    shouldAutorotateToInterfaceOrientation 中,您必须返回您想要支持的所有方向。

    因此,如果您希望您的应用仅在纵向上运行,请使用以下代码:

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

    如果你想支持所有可能的方向:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      • 2019-11-18
      相关资源
      最近更新 更多