iOS-具有自动布局的比例间距 [英] iOS - proportional spacing with autolayout

查看:64
本文介绍了iOS-具有自动布局的比例间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用界面生成器创建一个完全按比例缩放的视图.到目前为止,一切都很好.我正在以编程方式缩放字体,按钮等.唯一的问题是元素之间的约束(间距)保持不变.我想避免为间距约束创建出口,因为它看起来很杂乱.我希望元素之间的间距在我拉伸元素时保持成比例.现在,所有内容都根据屏幕的左侧对齐.如果我扩大视野,一切都会保持一致.我希望它们全部按比例伸展.我该如何做到这一点(最好使用界面生成器)?

I'm trying to create a perfectly to-scale view with interface builder. So far, everything is good. I'm scaling the font, buttons, etc programmatically.. the only problem is the constraints (the spacing) between elements which remains the same. I want to avoid creating outlets for the spacing constraints because it seems messy. I want the spacing between elements to remain proportional as i stretch the element. right now everything is aligned based on the left side of the screen. if i stretch my view, everything stays left aligned. I want it to all stretch apart proportionally. How can I accomplish this (preferably using interface builder)?

推荐答案

注意-这是一种粗略的方法.

Note - this is kind of a sketchy way of doing it.

我遇到了类似的问题,并通过在对象之间添加虚拟视图来表示它们之间的间距来解决该问题.您可以约束虚拟视图以使其与其余视图成比例地缩放,这将使对象之间的间距随整体大小正确缩放.我设置了虚拟视图的hidden属性,以使它们不会显示(请注意-隐藏后它们仍会正确布局).

I had a similar issue and resolved it by adding dummy views between my objects to represent the spacing between them. You can constrain the dummy views to scale proportionally to the rest of your views, which will make the spacing between your objects scale properly with the overall size. I set the hidden property of my dummy views so they wouldn't show up (note - they still get laid out properly when they are hidden).

希望有帮助.

此方法并不完美(您必须用多余的视图使IB杂乱无章),但是就像@sha所说的那样,这似乎是完成它的唯一方法. 事实证明,其他人也一直在提供类似的建议.我发现这些参考资料可能会有所帮助:

This method is imperfect (you have to clutter IB with extraneous views), but like @sha says it seems to be the only way to get it done. It turns out that other people have been giving similar advice. I came across these references which might be helpful:

自动布局以保持视图尺寸成比例

AutoLayout :布局一致性,比例元素间距为3.5英寸;和4英寸屏幕

这篇关于iOS-具有自动布局的比例间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆