简体   繁体   English

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

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

I'm new to the IOS development and I have to give landscape and Portrait only for one screen and all others should be portrait only.我是 IOS 开发的新手,我必须只为一个屏幕提供横向和纵向,而所有其他屏幕都应该是纵向的。 I use following code in AppDelegate file and change it in my screen.我在 AppDelegate 文件中使用以下代码并在我的屏幕中更改它。 But when I press back button previous screen not rotate to Portrait again?但是当我按下后退按钮时,前一个屏幕不会再次旋转到纵向?

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

Add below code inside viewWillAppear on all viewControllers you want to show portrait only.在您只想显示纵向的所有视图控制器上的 viewWillAppear 中添加以下代码。 don't forget to mark Device Orientation to both Portrait and Landscape modes.不要忘记将设备方向标记为纵向和横向模式。

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

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

相关问题 iOS 中纵向和横向的屏幕方向(Objective-C) - Screen Orientation for Portrait and Landscape Orientation in iOS (Objective-C) 在 Objective-C 中更改屏幕方向时,如何解决日期选择器 UIView 的奇怪行为? - How to fix strange behavior of date picker UIView when changing screen orientation in Objective-C? 如何在iOS 8 / Swift中通过屏幕尺寸/方向更改来处理NSLayoutConstraints? - How to handle NSLayoutConstraints with screen size/orientation changes in iOS 8/Swift? 如何在iOS目标C中处理解析通知? - How to handle parse Notification in ios objective c? Objective c 如何在ios13中将方向设置为横向 - Objective c How to set orientation to landscape in ios13 如何锁定iOS中的屏幕,使其只有纵向方向? - How lock screen in iOS for it to have only portrait orientation? 当应用程序只有一个方向时如何旋转UIImage的方向 - How to rotate orientation of UIImage when application have only one orientation Objective C iOS 9锁定viewController纵向方向 - Objective C iOS 9 lock viewController portrait orientation iOS 如何在使用 AVAssetWriter 捕获视频时正确处理方向 - iOS how to correctly handle orientation when capturing video using AVAssetWriter 目标-c:仅横向 - Objective-c: landscape orientation only
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM