【问题标题】:Target orientation of iOS6 shouldAutorotateiOS6 的目标方向 shouldAutorotate
【发布时间】:2023-03-19 20:25:02
【问题描述】:

我想允许应该根据目标方向旋转

[[UIDevice currentDevice] orientation] 

然而,上面的代码在 shouldRotate 中使用时保持当前(旧)方向,而不是目标方向

- (BOOL) shouldAutorotate {

    return YES;
}

【问题讨论】:

    标签: cocoa ios6


    【解决方案1】:

    好的,我想通了。始终在 shouldAutorotate 中返回 YES,然后执行以下操作:

    - (NSUInteger)supportedInterfaceOrientations
    {
        if ([UIDevice currentDevice].orientation == UIDeviceOrientationLandscapeLeft) {
            // Allow if you can
        } else if ([UIDevice currentDevice].orientation == UIDeviceOrientationPortrait) {
            // Allow if you can
        }
        // so on
    }
    

    【讨论】:

      【解决方案2】:
      - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
      

      这种方法应该可以解决问题。 toInterfaceOrientation 保存目标方向。

      【讨论】:

      • 能否请您升级答案...那些已经降级我的其他答案...
      【解决方案3】:

      除了返回yes之外

      -(BOOL)shouldAutorotate
      {
      return YES;
      }
      

      你必须执行

      - (NSUInteger)supportedInterfaceOrientations
      {
          return UIInterfaceOrientationMaskLandscape;
      }
      

      可用的不同面具是:

      UIInterfaceOrientationMaskPortrait
      UIInterfaceOrientationMaskLandscapeLeft
      UIInterfaceOrientationMaskLandscapeRight
      UIInterfaceOrientationMaskPortraitUpsideDown
      UIInterfaceOrientationMaskLandscape
      UIInterfaceOrientationMaskAll
      UIInterfaceOrientationMaskAllButUpsideDown
      

      您可能还想看:

      https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/supportedInterfaceOrientations

      【讨论】:

      • 是的,我知道,但这不是我的问题的答案:( 如何检测目标方向
      • OP 询问如何检测目标方向,我们已经知道如果要自动旋转,我们应该返回 YES。
      猜你喜欢
      • 1970-01-01
      • 2012-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多