为什么自动布局约束不起作用? [英] Why auto layout constraints not working?

查看:196
本文介绍了为什么自动布局约束不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在IB中设置约束,例如

I'm setting constraints in IB like

但是当我在iPhone4上运行该应用程序时,它显示

But when i run the app on iPhone4 it shows

为什么最后三个按钮在iPhone4屏幕上无法正确显示?我的约束条件有误吗? -:这是我的视图层次结构:- UITabbarControlle -> UINavigationController -> UIViewController和选项卡栏控制器为rootviewcontroller.

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

-仅供参考,屏幕上没有任何约束(基本上自动布局对我不起作用).

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

推荐答案

您已将按钮设计为4英寸,但在3.5英寸上没有足够的空间容纳所有按钮.

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

另一方面,如果您有足够的空间来容纳3.5'中的所有按钮而没有顶部/底部空白,则可以在UIView中添加按钮(而不是滚动视图).将按钮放在视图中并在该视图上设置固定的宽度/高度.将视图居中,它将保持其大小(两个屏幕尺寸中都带有按钮)

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)

这篇关于为什么自动布局约束不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆