Why auto layout constraints not working?

久未见 提交于 2019-12-24 03:05:40

问题


I'm setting constraints in IB like

But when i run the app on iPhone4 it shows

Why last three buttons not shown properly on iPhone4 screen?is there any mistake in my constraints ? Edit:- This is my view hierarchy:- UITabbarControlle -> UINavigationController -> UIViewController and tab bar controller is rootviewcontroller.

Edit:- FYI there is no effect of any constraints on the screen(basically autolayout not working for me).


回答1:


You have designed the buttons on 4 inch and you don't have enough space on 3.5 for all of them.

One way to do this is to place scroll view over your view controller's view and add the buttons on the scroll view.You have to add constraint on the scroll view , to be fixed on each side (without width/height).

After that grab all the buttons and add constrains on each side and sizes , so they will be fixed

If you , on other hand, have enough space for all the buttons to fit in 3.5' without any top/bottom margins you can add the button in UIView (instead of scroll view). Place the buttons in the view and set fixed width/height on that view.Center the view and it will keep his size (with the buttons inside on both screen sizes)




回答2:


There is an issue in your constraints, you have to update them.

You can do as is shown on the image bellow:

Once done, you will see, the Orange lines under your buttons turned to blue.

I wish that helps you!




回答3:


Your view is probably within a UIScrollView which will extend your total contentheight. It is not related to the absolute height of your viewport.

However, what do you expect? Your 3 buttons would overlay to the next buttons, if your theoretical approach would work.

What you need to to do is to wire all buttons to each other and give the view a top and bottom constraint to the top and bottom layout. You probably need to adjust your view to be on full screen and not to extend to the bottom.

Hint: as long as something is 'yellow' you need to add further constraints.



来源:https://stackoverflow.com/questions/23783449/why-auto-layout-constraints-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!