[英]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.