Set Orientation to Portrait on iPhone

爱⌒轻易说出口 提交于 2019-12-13 02:21:34

问题


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?


回答1:


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.




回答2:


For previous controller:

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



回答3:


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.



来源:https://stackoverflow.com/questions/3309048/set-orientation-to-portrait-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!