xcode 如何在 iPad 应用程序上禁用横向?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33590272/
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 do I disable landscape-orientation on an iPad app?
提问by Eugene
I created a completely new, single-view iOS universal Swift app. Then, I unchecked "Landscape Left" and "Landscape Right" in the app settings. I ran it on my iPhone, and hooray, it stays in portrait mode no matter how I rotate my phone. Then I ran it on my iPad, and it rotates to anything. Even upside-down portrait mode, which wasn't enabled in the first place? Am I the only experiencing this? This happens in the iPad simulator as well when I rotate with command+arrow key.
我创建了一个全新的、单一视图的 iOS 通用 Swift 应用程序。然后,我在应用程序设置中取消选中“横向左侧”和“右侧横向”。我在我的 iPhone 上运行它,万岁,无论我如何旋转手机,它都保持纵向模式。然后我在我的 iPad 上运行它,它旋转到任何东西。即使是一开始没有启用的倒置纵向模式?只有我一个人经历过吗?当我用命令+箭头键旋转时,这也会发生在 iPad 模拟器中。
I also tried adding the following to ViewController.swift, and got the same result.
我还尝试将以下内容添加到 ViewController.swift,并得到相同的结果。
override func shouldAutorotate() -> Bool {
return false
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.Portrait
}
Is there no way to actually disable rotating away from portrait on iPad?
有没有办法在 iPad 上实际禁用旋转远离肖像?
回答by Pavan Gandhi
Its work perfectly. Dont need to write code for it.
它的工作完美。不需要为它编写代码。
First select project and then go in first tab "General".
首先选择项目,然后进入第一个选项卡“常规”。
Now select "Devices" option in Deployment info section is iPadand in that down select Device orientation.. In which remove checkmark from landscape Left, Right option
现在在部署信息部分选择“设备”选项是iPad并在其中选择设备方向..其中从横向左侧,右侧选项中删除复选标记
After done select it back device as universal and set device orientation as portrait..mode and remove check mark from landscape mode.
完成后选择它作为通用设备并将设备方向设置为纵向..模式并从横向模式中删除复选标记。
Now run your app in iPad and check that things. I hope it will be resolved.
现在在 iPad 上运行您的应用程序并检查这些内容。我希望它会得到解决。
回答by Tomasz Czy?ak
There are separate entries in Info.plist for iPhone and iPad supported orientations.
Info.plist 中有针对 iPhone 和 iPad 支持方向的单独条目。
- iPhone = UISupportedInterfaceOrientations
- iPad = UISupportedInterfaceOrientations~ipad
- iPhone = UISupportedInterfaceOrientations
- iPad = UISupportedInterfaceOrientations~ipad
You need to modify Info.plist and remove landscape entries for UISupportedInterfaceOrientations~ipad key.
您需要修改 Info.plist 并删除 UISupportedInterfaceOrientations~ipad 键的景观条目。
回答by EK Chhuon
Works for me!
对我有用!
Open info.plist
as source code, you will see these properties:
info.plist
作为源代码打开,您将看到以下属性:
UISupportedInterfaceOrientations
: For iPhoneUISupportedInterfaceOrientations~ipad
: For iPad
UISupportedInterfaceOrientations
: 对于 iPhoneUISupportedInterfaceOrientations~ipad
: 对于 iPad
Under UISupportedInterfaceOrientations~ipad
remove your unwanted orientation mode. In my case, I want only Portrait Mode so I removed the rest modes and then save it.
在UISupportedInterfaceOrientations~ipad
删除不需要的方向模式下。就我而言,我只想要纵向模式,所以我删除了其余模式然后保存。
Done! Good Luck
完毕!祝你好运
回答by Nostradamus
In Xcode 10 at least, for a universal app this feature is broken. For a universal app setting the orientation restriction by checking the relevant orientation only works for iPhone, you will need to go into the plist and remove the unwanted orientations under "Supported interface orientations (iPad)", where you will find all four orientations awaiting you regardless of what you checked. It's simply a bug in Xcode that apparently doesn't have a very high priority since it's been around for a while.
至少在 Xcode 10 中,对于通用应用程序,此功能已损坏。对于通过检查相关方向仅适用于 iPhone 来设置方向限制的通用应用程序,您需要进入 plist 并在“支持的界面方向(iPad)”下删除不需要的方向,您会在其中找到所有四个方向等着您不管你检查了什么。这只是 Xcode 中的一个错误,显然没有很高的优先级,因为它已经存在了一段时间。
回答by Kris Roofe
回答by MD.Sazid Hasan Dip
these process of override does not work now.. and only changing the UI supported interface oriatations for ipad in info.plist will only temporarily solve the problem but will create problem when you will go for app validation and app sumbmission to app store.. For successfully validating and submitting you have to also add the key
这些覆盖过程现在不起作用..并且仅在 info.plist 中更改 ipad 的 UI 支持的界面 oriatations 只会暂时解决问题,但会在您将应用程序验证和应用程序提交到应用程序商店时产生问题.. 对于成功验证并提交您还必须添加密钥
"UIRequiresFullScreen"
“用户界面需要全屏”
you have to modify the keys like this..
你必须像这样修改键..
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UIRequiresFullScreen</key>
<true/>
I have tested this...
我已经测试过这个...