xcode 在 iPhone 上将方向设置为纵向
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3309048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set Orientation to Portrait on iPhone
提问by 109221793
I have an application that consists of a login, 3 tables, and then an image.
我有一个应用程序,它由一个登录名、3 个表和一个图像组成。
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?
有没有办法做到这一点?
采纳答案by tc.
If the previous view controller only supports portrait (see shouldAutorotateToInterfaceOrientation:
) then it should automatically rotate.
如果之前的视图控制器只支持纵向(参见shouldAutorotateToInterfaceOrientation:
),那么它应该自动旋转。
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).
如果以前的视图控制器支持横向,但如果它最初是纵向的,您希望它旋转为纵向,则可以通过更改shouldAutorotateToInterfaceOrientation:
导航返回时返回的内容来强制它。我不会推荐这个;它是不一致的用户界面(并且弄清楚正在发生的导航有点乏味)。
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.
有多种方法可以设置视图控制器界面方向(-[UIDevice setOrientation:]
将尝试触发自动旋转),但是您将进入私有 API 和潜在拒绝的领域。
回答by iutinvg
For previous controller:
对于以前的控制器:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
return YES;
}
return NO;}
回答by klaaspieter
Override shouldAutorotateToInterfaceOrientation:
in your table view controller and only return the orientation you want.
shouldAutorotateToInterfaceOrientation:
在您的表视图控制器中覆盖并仅返回您想要的方向。
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.
这可能不是真正切换回方向,因此,如果仅此不工作,你可能会要求setStatusBarOrientation:animated:
对UIApplication
您的表视图控制器viewWillAppear:
或viewDidAppear:
方法。