简体   繁体   中英

Set Orientation to Portrait on iPhone

I have an application that consists of a login, 3 tables, and then an image.

You can rotate the image to landscape mode but what I want to be able to do is when the 'back' button is pushed and the app returns to the previous screen, I was the app to automatically rotate to give a portrait view.

Is there any way of doing this?

For previous controller:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
    return YES;
}
return NO;}

If the previous view controller only supports portrait (see shouldAutorotateToInterfaceOrientation: ) then it should automatically rotate.

If the previous view controller supports landscape but you want it to rotate to portrait if it was originally in portrait, you can probably force it by changing what shouldAutorotateToInterfaceOrientation: returns when navigating back. I wouldn't recommend this; it's inconsistent UI (and it's a bit tedious to figure out what navigation is going on).

There are various ways to set the view controller interface orientation ( -[UIDevice setOrientation:] will attempt to trigger an autorotation), but then you're into the realm of private APIs and potential rejection.

Override shouldAutorotateToInterfaceOrientation: in your table view controller and only return the orientation you want.

This might not actually switch back the orientation, so if this alone doesn't work you might have to call setStatusBarOrientation:animated: on UIApplication in your table view controller's viewWillAppear: or viewDidAppear: methods.

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