Joe Cade
Joe Cade

Reputation: 387

Is there a way to run .frame.origin.y before the auto layout

I im using autolayout and have aligned text fields to each-other. But now that the whole app is ready, there is a special case where eveything will be hidden except ONE text field. So Im moving this text field up with .frame.origin.y

The problem is that this text field now appears in the middle for a second, because autolauout does its job first. I dont want to turn OFF autolayout entirely, i just want to be able to so SOMEHTING before autolauout.

I tried viewdidappear and the beginning of viewdidload

Upvotes: 0

Views: 182

Answers (1)

matt
matt

Reputation: 535989

Put your code into viewDidLayoutSubviews. That is the moment when autolayout is applied. Use a condition to make sure that your code runs only under the right conditions, because viewDidLayoutSubviews can be called many times during the course of your app's lifetime, and most of those times you will not want it to do anything special.

Be aware that changing the frame.origin.y is going to cause a conflict with your autolayout constraints. The correct way to do this sort of thing is to change the constraints. You will probably need to configure an outlet to the desired constraint so that you can refer to it in code; that way, you can just change that constraint's constant.

Upvotes: 1

Related Questions