Height of iOS8 Today Extension using Only Auto Layout Gives Broken Constraints

删除回忆录丶 提交于 2019-11-28 16:12:04
Ryan C.

After some experimenting, and stumbling across "what is NSLayoutConstraint "UIView-Encapsulated-Layout-Height" and how should I go about forcing it to recalculate cleanly" I determined that you can circumvent this problem using either "Height" & "Equal Heights" OR "Height" and Top and Bottom "Vertical Space" (as suggested by Guilherme Sprint), and then decreasing the "Priority" of the height constraint to 999.

This isn't the answer I was hoping for, but it does specify the height of the container via Auto Layout of the subview and avoids any warnings about broken constraints.

My entirely unscientific guess/assumption/conclusion is that iOS is correctly looking at the layout constraints to determine the height of the container view. It then adds a new constraint that is the same height as what it just calculated, but this now over-constrains the height. Reducing the priority on the original developer specified height constraint means the system generated constraint wins out and no warning is generated (would love to hear more about this from someone who actually knows).

You should define 5 constraints in total to make the Today Extension the size that you really want.

4 constraints will define the relation with the superview:

  • Top Space
  • Bottom Space
  • Leading Space
  • Trailing Space

By the way, you should hook this constraints to the layout margins, as Apple recommends for view, and specially Today Extensions.

The 5th constraint will be the Height for the subview. This constraint, together with the top and bottom spaces, will define the exact size of your section inside Today Tab.

Just explaining that, the height constraint will set a constant for the subview, and the top and bottom constraints will "glue" the superview to the subview edges.

Freeman

The height of the label makes it impossible to satisfy at the same time these constraints:

  • Label minimum height
  • Top Space to Superview
  • Bottom Space to Superview

You can solve it by removing the Bottom Space to Superview constraint, and the autolayout system will assign bottom space the remaining space.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!