【问题标题】:Support all orientations without autorotate in iPhone支持所有方向,无需在 iPhone 中自动旋转
【发布时间】:2017-10-10 06:21:51
【问题描述】:

启动屏幕之后的视图需要以设备的方向呈现,但一旦呈现就不应自动旋转到其他方向。我使用了这段代码:

- (BOOL)shouldAutorotate {

    [super shouldAutorotate];

    return YES;
}

-(UIInterfaceOrientationMask) supportedInterfaceOrientations {

    [super supportedInterfaceOrientations];

    return UIInterfaceOrientationMaskAll;
}

这适用于 iPad,但在 iPhone 中,将 shouldAutorotate 设置为 NO 只会导致纵向。这是正常行为吗?如果是这样,如何在 iPhone 中支持所有方向而无需自动旋转,仅适用于特定的视图控制器?

【问题讨论】:

    标签: ios objective-c iphone uiviewcontroller uiinterfaceorientation


    【解决方案1】:

    您需要在启动时检测设备处于什么方向:

    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    

    将其转换为界面方向:

    switch (orientation) {
        case UIDeviceOrientationLandscapeRight:
            return UIInterfaceOrientationLandscapeLeft;
        default:
            return UIInterfaceOrientationLandscapeRight;
    }
    

    现在将其存储在某个地方以供全局访问并返回:

    - (UIInterfaceOrientationMask) supportedInterfaceOrientations {
        return globalOrientation;
    }
    

    【讨论】:

      猜你喜欢
      • 2013-01-03
      • 1970-01-01
      • 2016-12-19
      • 2012-06-17
      • 1970-01-01
      • 1970-01-01
      • 2014-10-12
      • 1970-01-01
      • 2011-09-24
      相关资源
      最近更新 更多