There are 2 separate things here.
- Understanding
layoutSubviews()
. I.e. when and where to use it.
- How to achieve what you want to do the right way. I.e. doing something with the
UITextView
at device rotation.
About the layoutSubviews()
, you should not put any logic here as your view is not having any sub views.
You may say that we expect iOS to call it, so we can put some implementation here, but again, that is not the right way. layoutSubviews()
is not meant to alter the view itself, but just laying out sub views.
I would recommend reading more on layoutSubviews()
. I learnt from here, when I started learning iOS.
Now to achieve what you want to do, i.e. do something at the time of device rotation, you proper way is to use viewWillTransition(to:with:)
method of UIViewController
.
In this method, you can put logic to do something just before the transition will happen.
And you can also put logic which will execute during the transition OR after the transition completes, using the UIViewControllerTransitionCoordinator
parameter passed to viewWillTransition(to:with:)
Hope this helps!