简体   繁体   中英

Adding vertical spacing constraint causes conflicts with height

I am just playing around with autolayout. In my View i added a label on top, below that label i added a textfield and below that another textfield. Each one of them i wanted to have a fixed height. I added the constraints and it works fine. Then i wanted to add a button at the bottom side of the view. I added the button and then i used add missing constraints option. It worked but on iphone 4s i noticed that the button was overlapping the second textfield. So i thought that i should add a vertical spacing constraint between the textfield and the button. When i add it i got autolayout conflicting. Could you please explain to me why is this happening and how can it be solved? Any help appreciated.

在此处输入图片说明

Logical hight of screen of iPhone 4s in points is 480. Using "add missing constraints", constrains were added to support screen height of device you have on storyboard. If its iPhoneX, for example, the screen height is 812. You have fixed heights for all views and fixed spacings between them. Sum of all spacings and heights on screenshot is 798+. So this layout simply not fit iPhone 4s or other devices with smaller screen height.

Way to fix it - set constraint between login button and textfield (346.3 on screenshot) to greater than equal 10, to set minimum space and let it resize on different screen heights. And I not recommend to use auto adding of constraints.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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