简体   繁体   English

约束不起作用

[英]Constraints not working

I am not sure why but I have having so much trouble with constrains and auto layout. 我不确定为什么,但是我在约束和自动布局方面遇到了很多麻烦。 I have the below view and I want to make it display as is shown but every single approach I take to get seems to be incorrect. 我有下面的视图,我想使其如图所示,但我采用的每种方法似乎都不正确。

I have been following this tutorial online Auto Layout Tutorial in iOS and I am rather trying to describe my constraints. 我一直在关注iOS中的本教程在线自动布局教程,而我想尝试描述我的约束。 Following this technique this is what I have: 按照这种技术,这就是我所拥有的:

Description of my constraints. 我的约束条件的描述。

Label: 标签:

  • Centered in the view 以视图为中心
  • 51 from the top 顶51

All images: 所有图片:

  • Must have equal height and equal width. 必须具有相等的高度和相等的宽度。
  • Are separated from the left and right by a 0 gutter. 左右两个槽之间的距离为0。
  • All inner gutters separating the images are 12. 分隔图像的所有内部装订线均为12。

I have also included my storyboard. 我还包括了我的情节提要。 storyboard link 故事板链接

在此处输入图片说明

为此,您只需要声明第一个imageview的高度和宽度,并且ViewController使用相等的高度和相同的宽度,然后更改乘数默认值,将其调整为1即可调整大小,然后对于其余的imageview则给定相等的宽度和相同的高度第一个imageview。

If you want keep height and width constant , don't pin it, just use horizontal centre constraint. 如果要保持高度和宽度不变,请不要固定它,只需使用水平中心约束即可。 Pin it up using auto layout , hope this is helpful. 使用自动布局将其固定,希望对您有所帮助。

You are set image height and set image bottom constraint and does not set label height that you are many choice 您设置了图像高度并设置了图像底部约束,并且没有设置很多选择的标签高度

  • Set your label height because you run iPhone 4 or 4s that your label doesn't display. 设置标签高度,因为您运行的iPhone 4或4s不会显示标签。

  • remove your image bottom constraint because you are set fix image height. 删除图像底部约束,因为您已设置为固定图像高度。

  • you image doesn't fix height that remove your set image height and all image select and set equal height constraint (all image height same). 您的图片无法固定高度,因此无法删除您设置的图片高度以及所有图片选择并设置相等的高度限制(所有图片高度相同)。

Better You should move that four image views into a uiview(childView) .Make sure that 4 image views are the subviews of UIView. 更好您应该将这四个图像视图移到uiview(childView)中。确保4个图像视图是UIView的子视图。

-Add equal width and hight constraint to SuperView from the childView. -从childView向SuperView添加相等的宽度和较高的约束。 - Add multiplier value for the EqualHight and Equal Width constraints by selecting both constraints on storyboard(like 1:2.1,1:2.2).it may keep the same distance in all orientation -通过选择情节提要上的两个约束来增加EqualHight和Equal Width约束的乘数值(例如1:2.1,1:2.2),它在所有方向上都可以保持相同的距离

  • Add Y position and X position by trailing space and leading space, centre vertical in container. 通过在容器中垂直放置尾部空间和前导空间来添加Y位置和X位置。

  • Then Select the 4 uiimageviews and make sure they have same width and hight,after that 然后选择4个uiimageviews,并确保它们具有相同的宽度和高度,之后

  • select 4 image views then click the pin button and check the equal width and equal hight. 选择4个图像视图,然后单击大头针按钮并检查等宽和等高。

  • Add leading ,top and trailing space for image1 为image1添加开头,顶部和结尾空间

  • [1,2] [1,2]

    [3,4] [3,4]

  • add trailing and top space for image 2 为图像2添加尾部和顶部空间

  • add leading ,top and bottom space for image 3 为图像3添加开头,顶部和底部空间
  • add trailing ,top and bottom space for image 4, 为图像4添加尾部,顶部和底部空间,

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

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