Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where to update constraint in view controller life cycle

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

like image 839
Shankar Naik Avatar asked Nov 18 '25 11:11

Shankar Naik


1 Answers

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.

like image 167
Duncan C Avatar answered Nov 21 '25 02:11

Duncan C



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!