简体   繁体   English

我应该在新的Xcode项目中使用autolayout吗?

[英]Should I use autolayout in my new Xcode project?

Auto layout makes things easy but still confuses me a lot when it comes to landscape orientation. 自动布局使事情变得简单但在横向方向上仍然让我感到困惑。 I have to keep both landscape as well as portrait screen. 我必须保持风景和肖像画面。 My application will be for iPhones only ie from iPhone 5 to iPhone 6s+. 我的应用程序仅适用于iPhone,即从iPhone 5到iPhone 6s +。

What size class I need to use? 我需要使用什么尺寸的课程? everything seems so confusing. 一切似乎都很混乱。 Every constraints conflict with each other. 每个约束都相互冲突。 I have no problem in understanding leading, top, bottom, trail space. 我对领先,顶部,底部,小道空间的理解没有任何问题。 But what if device is rotated? 但是如果设备旋转怎么办? How do I manage things? 我该如何管理? Please help! 请帮忙!

I don't think you'll need size classes unless you're sure that there's going to be a significant GUI variations between different screen sizes or rotations. 我不认为你需要大小类,除非你确定在不同的屏幕尺寸或旋转之间会有明显的GUI变化。

In terms of rotation, the constraints don't change their orientation when the device is rotated. 在旋转方面,约束在旋转设备时不会改变它们的方向。 They still stand for what they stood for before. 他们仍然支持他们之前的立场。

For size classes, it depends on the app's design. 对于大小类,它取决于应用程序的设计。 Most likely, if you've setup your constraints correctly, you'll be fine with just a single size class for an entire family of devices. 最有可能的是,如果您正确设置了约束,那么对于整个系列的设备,只需一个大小的类就可以了。

If you choose to, for example, have significant changes in a tablet-focused variation, you can make those in code depending on the device type or screen size, or use a size class. 例如,如果您选择在以平板电脑为中心的变体中进行重大更改,则可以根据设备类型或屏幕大小在代码中进行更改,或使用大小类。 Only use a size class to have variations in layout between various screen sizes that cannot be handled with constraints alone. 仅使用大小类来在各种屏幕大小之间进行布局变化,而这些大小不能仅通过约束来处理。

This site is a useful visual reference for size classes. 此站点是大小类的有用的可视参考。

If you're making an iPhone-only app, what you basically need to know is that every iPhone uses regular height in portrait, and compact height in landscape. 如果您正在制作仅限iPhone的应用程序,那么您基本上需要知道的是,每个iPhone都使用常规高度的纵向和紧凑的高度。 So focus on those two size classes. 所以关注这两个大小的类。

Set the storyboard size class (in the bar under the canvas) to wAny hRegular. 将故事板大小类(在画布下的栏中)设置为wAny hRegular。 Then select your view controller and (in the Attributes inspector) set the size to iPhone 4-inch (or other device of your choice) and set the orientation to portrait. 然后选择视图控制器并(在“属性”检查器中)将大小设置为iPhone 4英寸(或您选择的其他设备)并将方向设置为纵向。 (These view controller settings don't interact with the size class but make it easier to see how things will look at runtime.) Now set up your portrait layout constraints. (这些视图控制器设置不与大小类交互,但可以更容易地看到事物在运行时的外观。)现在设置纵向布局约束。

Then set the size class to wAny hCompact. 然后将size类设置为wAny hCompact。 Change the view controller's orientation to Landscape. 将视图控制器的方向更改为横向。 Now set up your landscape layout constraints. 现在设置您的横向布局约束。

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

相关问题 Xcode 8自动布局破坏了我的项目 - Xcode 8 autolayout has ruined my project 我应该在xcode项目中将文件添加到哪些目标 - What targets should I be adding my files to in my xcode project 如何在Xcode中成功使用AutoLayout和Constraints? - How do I successfully use AutoLayout and Constraints in Xcode? 我应该使用自动布局进行手势拖动,旋转,缩放吗? - Should I use autolayout for gesture dragging, rotating, scaling? 如何从1 xcode项目中保存所有构建设置并在其他xcode项目中使用它们? - How can I save all my build settings from 1 xcode project and use them on other xcode projects? 我是否应该在我的Xcode项目中放置启动图像和应用程序图标 - Should I place Launch Images and App Icons inside my Xcode project 在上传到github之前,我应该隐藏iOS Xcode项目中的哪些文件? - Which files in my iOS Xcode project should I hide before uploading to github? 在旧Xcode的旧项目中使用新Xcode内置的框架 - Using framework builded in new Xcode in my old project in old Xcode 如何使用Autolayout在我的UIScrollview上设置约束? - How can I use Autolayout to set constraints on my UIScrollview? 我的 Xcode 8 有什么问题? 我什至不能编译新项目? - What's wrong with my Xcode 8? I cant even compile new project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM