Where should I be setting autolayout constraints when creating views programmatically

后端 未结 8 604
不思量自难忘°
不思量自难忘° 2020-12-07 07:52

I see different examples where constraints are set. Some set them in viewDidLoad / loadView (after the subview was added). Others set them in the m

8条回答
  •  囚心锁ツ
    2020-12-07 08:26

    This should be done in ViewDidLoad, as per WWDC video from Apple and the documentation.

    No idea why people recommend updateConstraints. If you do in updateConstraints you will hit issues with NSAutoresizingMaskLayoutConstraint with auto resizing because your views have already taken into account the auto masks. You would need to remove them in updateConstraints to make work.

    UpdateConstraints should be for just that, when you need to 'update' them, make changes etc from your initial setup.

提交回复
热议问题