iOS Autolayout标签位于图像顶部

时间:2015-09-18 14:28:32

标签: ios objective-c autolayout

我正在尝试实现UIPageController,以便我的用户可以在库中左右滑动。 UIImageView将占据整个背景,而标签将位于堆叠的顶部。这是我在界面构建器中的尝试:

1

UIImageView的大小检查器,因为下面的注释: 1

但是我在接口构建器中遇到了很多错误:

2015-09-18 22:19:33.964 ParksonUI[10525:453297] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7aec77f0 V:[_UILayoutGuide:0x7aec7330]-(449)-[UILabel:0x7aec6ca0'Over 200 Tips and Tricks']>",
    "<NSLayoutConstraint:0x7aec78b0 V:[UILabel:0x7aec6ca0'Over 200 Tips and Tricks']-(20)-[_UILayoutGuide:0x7aec7440]>",
    "<_UILayoutSupportConstraint:0x7aec5ee0 V:[_UILayoutGuide:0x7aec7330(64)]>",
    "<_UILayoutSupportConstraint:0x7aec6690 V:|-(0)-[_UILayoutGuide:0x7aec7330]   (Names: '|':UIView:0x7aec7270 )>",
    "<_UILayoutSupportConstraint:0x7aec6540 V:[_UILayoutGuide:0x7aec7440(0)]>",
    "<_UILayoutSupportConstraint:0x7aec7220 _UILayoutGuide:0x7aec7440.bottom == UIView:0x7aec7270.bottom>",
    "<NSLayoutConstraint:0x7afea660 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7aec7270(519)]>"
)

我认为标签可能会被推到图像下方?

2 个答案:

答案 0 :(得分:1)

首先,请确保在文档大纲中的标签之前有imageView,正如一些研究员所提到的那样。 之后,将imageView调整为主视图的所有边框,并尝试以下约束:

  • 底部空间:Superview
  • 将跟踪对齐:Superview
  • 对齐导致:Superview
  • 将顶部对齐:Superview

这些标签:

  • 底部空间到底部布局:期望的距离
  • 与Superview保持一致:理想的距离
  • 宽度:DESIRED WITDH
  • 身高:渴望的高度

希望它有效。

答案 1 :(得分:0)

您在标签上有顶部和其他底部的约束。如果删除顶部约束,警告将消失。结果将是正确的。您可以将宽度和高度约束添加到标签而不是顶部约束。 我希望能帮到你。