如何管理自动布局中两个视图之间的间隙 [英] How to manage the gap between two views in auto layout

查看:17
本文介绍了如何管理自动布局中两个视图之间的间隙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的 ViewController 使用自动布局我知道如何使用约束以编程方式定义两个视图之间的间隙.我现在想做的是当屏幕尺寸增加时,也增加间隙.因为我的 UIViews 在 iphone 4s 和 5s 中正确定位,但在 6 和 6 plus 中它们位于屏幕的一小块区域.我知道添加乘数我们可以设置视图的纵横比,但是,当屏幕高度增加时,如何增加两个视图之间的差距.

I am using auto layout for my ViewController I know how to define the gap between two views using constraints programmatically. What I want to do now is when the screen size increase, increase the gap also. Because my UIViewsare positioned properly in iphone 4s and 5s but in 6 and 6 plus they are positioned in a small area of the screen. I know adding multiplier we can set the aspect ratio of a view but, how to increase the gap between 2 views when the screen hight increase.

更新

比如说这张图片,上面有一个标志请登录标签.

Let say this image,, there is a logo above this please login label.

这是我的垂直位置约束

V:|-70-[Title]-130-[lblFirst]-0-[lblSecond]-20-[textusername]-10-[txtpassword]-10-[btnLogin]

此标题是此请登录标签上方 130pix 的图像.我想在 iphone 6 和 6 plus 上增加这个 130

this Title is an image 130pix above to this Please Login label. I want to increase this 130 when it comes to iphone 6 and 6 plus

推荐答案

取一个 alpha 0 并清除颜色的 UIView 并使用它来代替 gap 并使用宽高比来用于 gap 和 top and bottom or left and无论您的情况如何,都可以根据您想要使差距动态化的观点.而且您还需要向 gapView 添加更多对齐约束,但它会起作用.我找不到任何其他方法可以轻松做到这一点,所以我在所有项目中的任何地方都使用了这种方法,并且一切正常.我认为具有清晰颜色和 alpha 0 的 UIView 不会以任何方式影响屏幕或性能.我们可以使用它.

Take a UIView with alpha 0 and clear color and use it instead of the gap and use aspect ratio to the view used for gap and top and bottom or left and right whatever your situation to the views between whom you want to make the gap dynamic. And also you need to add some more alignment constraints to the gapView but it will work. I could not found any other method to do this easily so i have used this method everywhere in all projects and all working fine. I think UIView with clear color and alpha 0 will not effect the screen or performance in any way. We can use this.

这是一个示例,例如,如果您有两个垂直文本字段,并且您想动态增加它们之间的间隙,然后在文本字段的宽度完全相同的情况下查看它们之间的视图并添加这些约束.

Here is an example like if you have two text fields vertically and you want to increase the gap between them dynamically then take a view between then with the exact same width of text field and add those constraints.

1) GapView 顶部到上方文本字段.

1) Top of GapView to upper text field.

2) GapView 底部到文本字段下方.

2) Bottom of GapView to below text field.

3) 与任何文本字段或父视图或主视图的前导和尾随宽度相等.

3) Equal width to any text field or leading and trailing to superview or main view.

4) 主视图的比例高度(您可以通过将子视图的相等高度添加到任何父视图然后更改乘数来添加此约束);

4) Proportional Height to main view(you can add this constraint by adding equal height from subview to any of superview and then by changing the multiplier);

并且你的 GapView 会相应的增加和减少.

And your GapView will increase and decrease accordingly.

这篇关于如何管理自动布局中两个视图之间的间隙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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