简体   繁体   中英

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. I use following code in AppDelegate file and change it in my screen. 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. don't forget to mark Device Orientation to both Portrait and Landscape modes.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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