Universal application with Portrait orientation for iPhone and Landscape orientation for iPad

半世苍凉 提交于 2019-12-03 04:43:41

问题


I'm creating a Universal application using Swift. I have used Storyboard and Auto-Layouts. Requirement is of creating a universal application which will support Portrait orientation only for iPhone and Landscape orientation only for iPad.

I have developed UI for iPhone and now I will be starting iPad UI.

Also UI created for iPhone is not same as UI created for iPad, both UI's are quite different.

I'm thinking of to create separate storyboards for iPhone and iPad. Is there any proper way to achieve this?


回答1:


Go to the info.plist file and add an array with key "Supported interface orientations (iPhone)" and add the following values in it:

  1. Portrait (bottom home button)

Similarly, add another array "Supported interface orientations (iPad)" and add the following:

  1. Portrait (bottom home button)
  2. Landscape (left home button)
  3. Landscape (right home button)

See below:




回答2:


If you are deploying your App to iOS 8 only, then I would use one storyboard. It is simpler to utilize one screen. Here is a link for a great tutorial. http://www.raywenderlich.com/83276/beginning-adaptive-layout-tutorial
If you are like me and want to target down to iOS 6, then I would use separate storyboards. Definitely stick with Auto Layout for whatever you decide to use.
Don't forget we must start supporting 64-bit.
Good luck!




回答3:


If you want to set this for a specific ViewController (allow all on iPad but only portrait on iPhone) put this into your ViewController-class (Swift 4):

override var supportedInterfaceOrientations:UIInterfaceOrientationMask {
    return UIDevice.current.userInterfaceIdiom == .pad ? UIInterfaceOrientationMask.all : UIInterfaceOrientationMask.portrait
}


来源:https://stackoverflow.com/questions/27782224/universal-application-with-portrait-orientation-for-iphone-and-landscape-orienta

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