简体   繁体   中英

Why auto layout constraints not working?

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).

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)

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!

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.

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