我怎么能让我在iOS 8.3SDK上用Swift编写的通用应用程序在iPhone上只支持纵向模式,而在iPad上同时支持纵向和横向模式?
我知道过去在AppDelegate中已经做到了这一点。我如何在Swift中做到这一点?
发布于 2015-05-30 02:55:30
你可以通过编程的方式来做,或者更好的是,你可以简单地编辑你项目的Info.plist (这应该更实用,因为它是一个全局设备配置)
只需添加“支持的接口方向(iPad)”键
发布于 2015-05-30 02:36:01
你可以通过编程的方式来完成。
override func shouldAutoRotate() -> Bool {
if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
return true
}
else {
return false
}
}
然后
override func supportedInterfaceOrientations() -> Int {
return UIInterfaceOrientation.Portrait.rawValue
}
或您希望在默认情况下具有的任何其他旋转方向。
这应该会检测到你正在使用的设备是否是iPad,并且只允许在该设备上旋转。
编辑:由于您只想在iPhone上显示肖像,
override func supportedInterfaceOrientations() -> Int {
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
return UIInterfaceOrientation.Portrait.rawValue
}
else {
return Int(UIInterfaceOrientationMask.All.rawValue)
}
}
发布于 2018-11-15 04:33:23
我不确定Chris的答案是否仅仅通过复制和粘贴"Supported orientations (iPad)“键来工作;可能不是从info.plist
的XML源判断。以实现不同方向的支持。您可以打开info.plist
XML源并按如下所示进行编辑:
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
xcode UI提供了一种简单的方法。转到您的项目设置。在"General“选项卡中选择您的目标,然后在"Deployment Info”部分中,您可以首先选择iphone/ipad,并分别标记您希望为每个设备支持的设备方向,然后将设备更改为"Universal“。它将在幕后生成上面的xml。
此处的“通用”选项显示了在iPhone和iPad之间通用的选项。
https://stackoverflow.com/questions/30536616
复制相似问题