Centering subview's X in autolayout throws “not prepared for the constraint”

前端 未结 8 1252
予麋鹿
予麋鹿 2020-11-30 02:09

I have a custom UIView subclass which is being initialized via a nib.

In -awakeFromNib, I\'m creating a subview and attempting to center it in its super

8条回答
  •  北海茫月
    2020-11-30 02:57

    This is an old question but I want to point out this line from the docs:

    When developing for iOS 8.0 or later, set the constraint’s isActive property to true instead of calling the addConstraint(_:) method directly. The isActive property automatically adds and removes the constraint from the correct view.

    At the very least, this will remove one point of failure since you no longer need to worry about calling addConstraint on the wrong view

提交回复
热议问题