简体   繁体   English

为什么自动布局约束不起作用?

[英]Why auto layout constraints not working?

I'm setting constraints in IB like 我在IB中设置约束 就像这张图片所示

But when i run the app on iPhone4 it shows 但是当我在iPhone4上运行该应用程序时 喜欢这张图片

Why last three buttons not shown properly on iPhone4 screen?is there any mistake in my constraints ? 为什么最后三个按钮在iPhone4屏幕上无法正确显示?我的约束条件有误吗? Edit:- This is my view hierarchy:- UITabbarControlle -> UINavigationController -> UIViewController and tab bar controller is rootviewcontroller . 编辑:-这是我的视图层次结构: UITabbarControlle -> UINavigationController -> UIViewController和选项卡栏控制器是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. 您已经在4英寸上设计了按钮,但在3.5英寸上没有足够的空间容纳所有按钮。

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). 另一方面,如果您有足够的空间将所有按钮容纳在3.5'中,而没有任何顶部/底部边距,则可以在UIView中添加按钮(而不是滚动视图)。 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. 您的视图可能位于UIScrollView ,这将扩展您的总内容高度。 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. 如果您的理论方法可行,则您的3个按钮将覆盖下一个按钮。

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. 提示:只要某些东西是“黄色”,您就需要添加其他约束。

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

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