简体   繁体   中英

Orientation is not changed when view is changed from portrait to landscape

I have menu that is portrait only and detail view (with UIWebView ) that can be portrait or landscape.

When I enter detail view and rotate device landscape and go back from that screen in that way to menu which should only be portrait then menu is in landscape orientation (along with status bar and navigation bar).

Is there a way to avoid this and force screen to be rotated to desired (supported) orientation?

Proposed solution by @kkumpavat didn't worked for me or it wasn't clear enough for me to understand it. I did more searching and found solution which uses:

    // http://stackoverflow.com/questions/181780/is-there-a-documented-way-to-set-the-iphone-orientation
    // http://openradar.appspot.com/radar?id=697
    [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:")
                                   withObject:UIInterfaceOrientationPortrait];

but this was generating annoying warnings and I've swapped it with:

//force update of screen orientation
if (self.interfaceOrientation != [self preferredInterfaceOrientationForPresentation]) {
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger: [self preferredInterfaceOrientationForPresentation]]
                                forKey:@"orientation"];
}

called from NavigationController's viewDidAppear .

Change viewWillAppear of menu viewController as below

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    UIViewController *controller = [[UIViewController alloc] init];
    [self presentViewController:controller animated:NO completion:nil];
    [self dismissViewControllerAnimated:NO completion:nil];
}

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