【问题标题】:Force a UIViewController to load a certain orientation强制 UIViewController 加载某个方向
【发布时间】:2012-01-12 04:15:00
【问题描述】:

所以在我的应用程序中,我有一个导航堆栈,用户可以在其中浏览各种 viewController。一些视图支持多个方向,而其中一个视图不支持。所以我的问题是,我怎样才能强制一个特定的 UIViewController 只在一个方向上显示。我需要这个在第一次加载视图时工作,当另一个视图被弹出并且这个视图再次可见时。谢谢

我实现了这两种方法来控制视图的旋转:

-(void)orientationDidChange:(NSNotification *)notification
-(BOOL)shouldAutoRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

谢谢

【问题讨论】:

  • 你能发布你对上述委托方法的实现吗?
  • 这个问题已经被问过很多次了:stackoverflow.com/questions/3538796/…。简而言之,重写该方法并更改返回值以仅支持您想要的方向。
  • 在我问之前我试过了 - 不工作

标签: iphone ios ipad rotation uiinterfaceorientation


【解决方案1】:
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

【讨论】:

    【解决方案2】:

    答案: shouldAutoRotateToInterfaceOrientation 类的UIViewController 方法。

    如果您的UIView 支持方向,则此函数返回YES。如果您将return YES 仅添加到landscape orientation,那么每当您加载该视图时,iPhone/iPad 将自动置于该方向。

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Return YES for supported orientations
        return (interfaceOrientation == UIInterfaceOrientationLandscape);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-23
      • 1970-01-01
      • 2016-11-24
      • 2013-02-26
      • 2023-03-05
      • 2010-10-27
      相关资源
      最近更新 更多