xcode 如何在 iPhone 应用程序上仅支持纵向模式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10032490/
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
How to support only portrait mode on an iPhone app
提问by Eyal
I have a strange problem in an iPhone app I'm developing. I want my app to support ONLYportrait mode, but for some reason I can't do it (device & simulator).
我正在开发的 iPhone 应用程序中遇到一个奇怪的问题。我希望我的应用程序仅支持纵向模式,但由于某种原因我不能这样做(设备和模拟器)。
To support only portrait mode I did as follow:
为了仅支持纵向模式,我执行了以下操作:
- In the TARGET summary section on Xcode, I chose only portrait.
- All my ViewControllers implements
shouldAutorotateToInterfaceOrientation
- 在 Xcode 的 TARGET summary 部分,我只选择了肖像。
- 我所有的 ViewControllers 实现
shouldAutorotateToInterfaceOrientation
But as I said it won't work, and the strange result is that the app support ALLthe orientations (portrait, upside down, landscape left, landscape right).
Any ideas?
但正如我所说它不会工作,奇怪的结果是该应用程序支持所有方向(纵向、倒置、横向左侧、右侧横向)。
有任何想法吗?
this how I implement shouldAutorotateToInterfaceOrientation
这就是我实施的方式 shouldAutorotateToInterfaceOrientation
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
NSLog(@"Checking orientation %d", interfaceOrientation);
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
I notice just nowthat when I rotate the phone I get this message:
我刚刚注意到,当我旋转手机时,我收到了这条消息:
"Two-stage rotation animation is deprecated. This application should use the smoother single-stage animation."
“不推荐使用两阶段旋转动画。此应用程序应使用更流畅的单阶段动画。”
What does it means?
这是什么意思?
回答by Eric
On the Target Summary choose portrait only.
在目标摘要上,仅选择纵向。
回答by rohan-patel
Go to info.plist file. Right Click open it as source code. And look for this line. For me in iPad its like this:
转到 info.plist 文件。右键单击将其作为源代码打开。并寻找这条线。对我来说,iPad 是这样的:
<key>UISupportedInterfaceOrientations~ipad</key>
Delete all other orientation and keep the only one which you need..Like this :
删除所有其他方向并保留您唯一需要的方向..像这样:
<array>
<string> UIInterfaceOrientationPortrait </string>
</array>
回答by Dondragmer
It is possible to have multiple ViewControllers on the screen. The UITabBarControlleris itself a UIViewController, and it only passes shouldAutorotateToInterfaceOrientation:requests to the viewControllers within if it chooses. The default implementation does this, but if you subclass it, the code XCode generates (as of iOS 5.1) does not.
屏幕上可以有多个 ViewController。TheUITabBarController本身就是 a UIViewController,shouldAutorotateToInterfaceOrientation:如果它选择,它只会将请求传递给其中的 viewControllers 。默认实现是这样做的,但是如果您将其子类化,则 XCode 生成的代码(从 iOS 5.1 开始)不会。
回答by Jesse Naugher
check your plist and make sure the key there is set correctly.
检查您的 plist 并确保那里的密钥设置正确。

