美文网首页程序员iOS学习iOS开发进阶
xcode8 SizeClass适配iPhone 和 ipad

xcode8 SizeClass适配iPhone 和 ipad

作者: 朝雨晚风 | 来源:发表于2017-10-13 18:43 被阅读747次

(一)sizeClass 适配横竖屏举例

创建一个 .xib 文件,在Interface Builder 中看到下面的界面是可以选择横竖屏的,但是此时设置的constraint 是针对所有size classes 的,包括横竖屏。


未特别设置的默认 sizeclass 布局.png

适配不同情况下的布局关键在于vary for Traits 按钮,点击这个按钮之后会有一个弹出框如下图,这里你可在同一个 .xib文件选择横竖屏不同的布局约束。


vary for Traits 按钮.png

例如点击横屏,选择Height,选择之后,整个区域变成蓝色,此时在向.xib 中添加的约束就是当前选择的屏幕独有的约束啦,这里将 view 的高度变成 200。最后,点击Done Varying 按钮就可以了。


横屏布局约束.png

运行效果:


竖屏.png 横屏.png

(二)适配 ipad 布局

苹果要求 iPhone 应用必须能在ipad 上正常使用,即使你只想开发给iPhone 用户使用,因为苹果测试人员是使用ipad 测试你的应用,如果你的布局在 ipad 上有错乱重贴影响使用被发现了是会被拒绝的。幸运的的是你不需要做其他什么操作,sizeClass 的自动适配布局已经包含了 ipad 布局了,你要做的只是如下简单操作。

Guideline 2.4.1 - Performance - Hardware Compatibility

We noticed that your app did not run at iPhone resolution when reviewed on iPad running iOS 10.3.2. 

Specifically, the main page was jagged on iPad. Please see attached screenshots for details.

Next Steps

To resolve this issue, please revise your app to ensure it runs and displays properly at iPhone resolution on iPad. Even if your app was developed specifically for iPhone, users should still be able to use your app on iPad. 

Resources

For information on iOS device screen sizes and resolutions, please review the iOS Human Interface Guidelines as well as Points versus Pixels in the View Programming Guide for iOS.
适配 ipad.png
所以你需要勾选universal,并且勾选 Requires full screen 复选框,不勾选提交 app 的时候回报如下错误,之外你需要准备ipad 的启动图尺寸、ipad icon 图尺寸和 ipad 上线 预览图尺寸,具体可参考iOS iPhone 和 iPad 启动图设置
ERROR ITMS-90475: "Invalid Bundle. iPad Multitasking support requires launch story board in bundle 'xxxx'."
ERROR ITMS-90474: "Invalid Bundle. iPad Multitasking support requires these orientations: 'UIInterfaceOrientationPortrait,UIInterfaceOrientationPortraitUpsideDown,UIInterfaceOrientationLandscapeLeft,UIInterfaceOrientationLandscapeRight'. Found 'UIInterfaceOrientationPortrait' in bundle 'xxxx'."

相关文章

网友评论

    本文标题:xcode8 SizeClass适配iPhone 和 ipad

    本文链接:https://www.haomeiwen.com/subject/gsxtuxtx.html