繁体   English   中英

如何在 IOS 目标 C 中处理方向仅适用于一个屏幕并在按下时重置

[英]How to Handle Orientation in IOS Objective C only for one screen and reset when press

我是 IOS 开发的新手,我必须只为一个屏幕提供横向和纵向,而所有其他屏幕都应该是纵向的。 我在 AppDelegate 文件中使用以下代码并在我的屏幕中更改它。 但是当我按下后退按钮时,前一个屏幕不会再次旋转到纵向?

- (UIInterfaceOrientationMask)application:(UIApplication *) application
  supportedInterfaceOrientationsForWindow:(UIWindow *) window {
    if (self.allowLandscape) {
        return UIInterfaceOrientationMaskLandscapeLeft &
        UIInterfaceOrientationMaskLandscapeRight;
    }
    return UIInterfaceOrientationMaskPortrait;
}

在您只想显示纵向的所有视图控制器上的 viewWillAppear 中添加以下代码。 不要忘记将设备方向标记为纵向和横向模式。

NSNumber *value = [NSNumber numberWithInt:UIDeviceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM