简体   繁体   English

ios自适应布局/尺寸类别以针对特定手机尺寸?

[英]ios adaptive layout / size classes to target specific phone size?

I've lost what's left of my mind messing with adaptive layout and size classes. 我已经把剩下的一切都弄乱了自适应布局和大小类。 Not that I was a genius to begin with, but now I'm bald. 刚开始我并不是天才,但现在我是秃头。

Say I have a very simple layout that I want to make sure looks perfect ( and by perfect I mean all my ui elements are present) on the 3.5, 4, 4.7 and 5.5 iphones. 说我有一个非常简单的布局,我想确保在3.5、4、4.7和5.5 iPhone上看起来完美(并且完美的意思是我的所有ui元素都存在)。

Ok, I start off in Any Any size, all the elements placed with constraints, no warnings, no errors. 好的,我以任何任意大小开始,所有元素都放置有约束,没有警告,没有错误。 Good to go. 好去。 Load up the various size phones in preview mode, 5.5 looks good, 4.7 looks good, 4 looks ok, 3.5 needs some work. 在预览模式下加载各种尺寸的手机,5.5看起来不错,4.7看起来不错,4看起来还可以,3.5需要一些工作。

I want to futz with 3.5 and 4 (NOT 4, 4.7 and 5.5) Are size classes the way to achieve this goal? 我想用3.5和4(NOT 4、4.7和5.5)来付诸实践,是否可以通过尺寸等级实现这一目标? Would I need to do multiple storyboards or do this or some type of device size checking in code? 我需要在代码中执行多个情节提要还是执行此操作或某种类型的设备大小检查? I came across one guy who went the route of multiple storyboards, seemed like a pretty big hack and a bunch of people were skeptical of his approach but I bet he still has hair. 我遇到了一个走过多个故事板的家伙,似乎是个很大的黑客,很多人都对他的做法持怀疑态度,但我敢打赌他仍然长头发。

I guess what I'm asking, can size classes be used to target a specific size? 我想我要问的是,尺寸类可以用于指定特定尺寸吗? If you want your layouts looking perfect on 3.5, 4, 4.7 and 5.5 what is the suggested way to go about this? 如果您希望布局在3.5、4、4.7和5.5上看起来完美,那么建议的解决方法是什么?

No, size classes can't really help you with that. 不,尺寸等级并不能真正帮助您。 And please don't do multiple storyboards. 并且请不要做多个情节提要。 It's hard to give some concrete advice without seeing your UI and what problems it has on smaller screens, but in most cases where your UI can't properly scale between sizes within the same size class, I'd say you should probably rethink your UI or your constraints. 在看不到用户界面以及在较小的屏幕上遇到什么问题的情况下,很难给出一些具体的建议,但是在大多数情况下,如果用户界面无法在相同尺寸级别的尺寸之间正确缩放,我想您应该重新考虑一下用户界面或您的约束。

In worst acceptable case you could have outlets to constraints that are problematic and update those from code depending on screen size. 在最坏的情况下,您可能会遇到有问题的约束,并根据屏幕大小从代码中更新约束。

Check out my answer here: 在这里查看我的答案:

https://stackoverflow.com/a/28093987/1135714 https://stackoverflow.com/a/28093987/1135714

As I said, AutoLayout isn't device-specific, but there's a workaround for that. 就像我说的,AutoLayout不是特定于设备的,但是有一种解决方法。 You can either place a UIView or set constraints via code (which is pretty easy). 您可以放置UIView或通过代码设置约束(这很简单)。

There is only one type of Size-classes named compact size is available for all iPhone Devices with different sizes. 只有所有不同尺寸的iPhone设备都可以使用一种尺寸类型,即紧凑尺寸。 So , the solution is 1. When you set constraint u have to set relation (Equal, greater than or equal or less than or equal ). 因此,解决方案是1。当您设置约束时,您必须设置关系(等于,大于或等于或小于或等于)。 This with help to resize your view or inter-spacing between views according to the size of current devices . 这有助于根据当前设备的大小调整视图的大小或视图之间的间距。

To get your expected look, we have to clear about the different constraint setting with high or low priority , relations , constraint value for different sizes(compact-regular, compact-compact, regular-regular, regular-compact). 为了获得您的期望外观,我们必须清除具有不同优先级,关系,不同大小的约束值的紧凑约束设置(compact-regular,compact-compact,regular-regular,regular-compact)。

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

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