简体   繁体   English

如何管理自动布局中两个视图之间的间隙

[英]How to manage the gap between two views in auto layout

I am using auto layout for my ViewController I know how to define the gap between two views using constraints programmatically. 我正在为ViewController使用自动布局,我知道如何以编程方式使用约束定义两个视图之间的间隙。 What I want to do now is when the screen size increase, increase the gap also. 我现在想做的是屏幕尺寸增加时,间隙也增加。 Because my UIViews are positioned properly in iphone 4s and 5s but in 6 and 6 plus they are positioned in a small area of the screen. 因为我的UIViews在iphone 4s和5s中正确放置,但在6和6s中则放置在屏幕的一小部分。 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. 我知道添加乘数可以设置视图的纵横比,但是当屏幕高度增加时,如何增加2个视图之间的间隙。

UPDATE 更新

在此处输入图片说明

Let say this image,, there is a logo above this please login label. 假设这张图片在此请登录标签上方有一个徽标。

This is my verticle position constraint 这是我的垂直位置限制

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

this Title is an image 130pix above to this Please Login label. 此标题是此“请登录”标签上方的图像130pix。 I want to increase this 130 when it comes to iphone 6 and 6 plus 我想在iPhone 6和iPhone 6 Plus上增加130

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. 取一个带有alpha 0的UIView并清除颜色,并使用它代替间隙,并对要用于间隙和动态间隙的视图使用纵横比来显示间隙和上下左右或左右。 And also you need to add some more alignment constraints to the gapView but it will work. 而且,您还需要向gapView添加更多对齐约束,但是它将起作用。 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. 我认为具有清晰色彩和alpha 0的UIView不会以任何方式影响屏幕或性能。 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) Top of GapView to upper text field. 1)GapView的顶部到上方的文本字段。

2) Bottom of GapView to below text field. 2)GapView的底部到下面的文本字段。

3) Equal width to any text field or leading and trailing to superview or main view. 3)等于任何文本字段的宽度,或者等于或小于超级视图或主视图的宽度。

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); 4)与主视图成比例的高度(您可以通过从子视图到任何父视图添加相等的高度,然后更改乘数来添加此约束);

And your GapView will increase and decrease accordingly. 并且您的GapView将相应地增加和减少。

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

相关问题 自动布局和UIViewAnimation-两个连接的视图之间的间隙 - Auto layout and UIViewAnimation - Gap between two connected views 如何使用自动布局在对象之间创建间隙 - How to use auto layout to create a gap between objects 自动布局:在单独的窗口中的两个视图之间创建约束 - Auto Layout: Create constraint between two views in separate windows 如何在iOS SDK中使用自动布局管理复杂的视图层次结构 - How to Manage Complicated Views Hierarchy using Auto-layout in iOS Sdk 使用自动布局调整两个视图的大小 - Resizing two views using auto layout 如何在两个自动布局约束之间切换? - How to switch between two auto-layout constraints? 如何在自动布局中的其他两个标签之间垂直居中放置标签 - How to vertically center label between two other labels in auto layout 如何使用Masonry DSL for Auto Layout定义视图之间的垂直和水平关系? - How do you define the vertical and horizontal relationship between views using the Masonry DSL for Auto Layout? 如何使用Auto Layout的视觉格式语言在超级视图的相对侧放置两个视图? - How can I position two views on opposite sides of a superview using Auto Layout's visual format language? 故事板减少视图之间的差距 - Storyboard reduce gap between views
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM