where to update constraint in view controller life cycle

1.8k Views Asked by At

I would like to update constraitn constants and multiplier and I would like to update these constraints in right view controller life cycle event

  • loadView

  • viewDidLoad

  • viewWillAppear

  • viewWillLayoutSubviews

  • viewDidLayoutSubviews

  • viewDidAppear

There are some posts saying its better to update constraints at UpdateViewConstraints method of viewcontroller

There is so much confusion related surrounding this.

Somebody please explain

1

There are 1 best solutions below

3
Duncan C On

Create your constraints in your storyboard. Control-drag from your constraints into your source file to create outlets to those constraints.

Then, in your button IBAction method, update the constant values to the constraints and call layoutIfNeeded().

As Paul said in his comment, if you're creating your views in code, also create your constraints in code and save them to properties in your view controller, then use those properties in your button IBAction like described above.