简体   繁体   English

为不同屏幕制作ViewController的最佳方法

[英]The best way to make a viewcontroller for different screens

I would like to know which is the best way to make a view controller for iOS 9 swift 2 xcode 7, for different iPhone screens? 我想知道哪种方法可以为不同的iPhone屏幕制作适用于iOS 9 swift 2 xcode 7的视图控制器?

I have tried to make it with constrains but from iphone 4s to iphone 6s screens we can see wide gaps between the icons and text fields etc. 我试图通过约束使其实现,但是从iphone 4s到iphone 6s屏幕,我们可以看到图标和文本字段之间的巨大差距。

What i'm thinking is to make different view controllers for each screen (5.5inches, 4.7inches, 3.5inches) and to make my app check with which screen the user is opening the app and load the unigue view controller for this screen. 我在想的是为每个屏幕(5.5英寸,4.7英寸,3.5英寸)制作不同的视图控制器,并让我的应用检查用户正在打开哪个屏幕并为此屏幕加载唯一视图控制器。

Or maybe there is a better way but im new to swift 2.0 so i'm asking for your help! 也许还有更好的方法,但是我是Swift 2.0的新手,所以我正在寻求您的帮助!

Thanks a lot for your time. 非常感谢您的宝贵时间。

You can make a views for multiple screens using autolyout and size classes. 您可以使用autolyout和size类为多个屏幕创建视图。 You have proportional constraints that fit on all screens. 您具有适合所有屏幕的比例约束。

Proportional constraints means you can set for example view1 is 50% of screen. 比例约束意味着您可以设置例如view1是屏幕的50%。 These constraints fit on all screens. 这些限制适用于所有屏幕。

Avoid excessive use of size classes (applying constraint in different size class). 避免过度使用大小类(在不同大小类中应用约束)。 Try to go with proportional constraints in hAny wAny layout. 尝试在所有布局中使用比例约束。

Only go for different size class if design on ipad is different then iphone. 如果iPad上的设计与iPhone不同,则仅适用于不同尺寸的尺寸。 Or if you need different font sizes on different devices. 或者,如果您在不同的设备上需要不同的字体大小。

https://developer.apple.com/library/ios/recipes/xcode_help-IB_auto_layout/chapters/EditingConstraintAttributesintheAttributesInspector.html https://developer.apple.com/library/ios/recipes/xcode_help-IB_auto_layout/chapters/EditingConstraintAttributesintheAttributesInspector.html

I think this depends upon what your requirement is and what you prefer. 我认为这取决于您的要求和偏好。
I usually prefer the good old Springs and Struts . 我通常更喜欢老式的Springs and Struts
They can be used by disabling auto layout and screen sizes. 可以通过禁用自动布局和屏幕尺寸来使用它们。
Using Springs and Struts i only create a single Storyboard to manage all iPhone and iPad screen sizes without any coding effort. 使用Springs and Struts我仅创建一个Storyboard即可管理所有iPhoneiPad屏幕尺寸,而无需进行任何编码。
No matter how complex the UI maybe, for me Springs and Struts are the best solution. 无论UI多么复杂,对我而言, Springs and Struts都是最佳解决方案。

Size classes give you a more fine grain control for different sizes and orientations. 尺寸类别为您提供了针对不同尺寸和方向的更精细的颗粒控制。 Please refer Apple's documentation 请参阅Apple的文档

As I understood your question that you want to load storyboard as size of screen of device. 据我了解,您想要将故事板作为设备屏幕尺寸加载的问题。

I will suggest you to refer this link to load a different storyboard depending on screen size. 我建议您参考此链接以加载不同的故事板,具体取决于屏幕尺寸。 Sorry for Objective c but hope it helps you. 对不起,目标c,但希望对您有所帮助。 Load different storyboards 加载不同的故事板

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM