Detecting UITextView size change in order to set its textContainerInset

In my `UITextView` subclass i want to set the `textContainerInset` at the top and bottom to be half of the textview height. I thought that setting it in `UIViewController.viewWillLayoutSubviews()` or `UIViewController.viewDidLayoutSubviews` of the hosting view controller would be a good idea, but doing so breaks the textview: when I select a word in it and drag one of the selection handles down, the textview automatically scrolls up. What is the best way to detect a size change for a textview?

textContainerInset` at the top and bottom to be half of the textview height


What result are you expecting ? That means that the sum of margins is equal to the textView height ?

Yes, although I don't mean the content height, only the frame height, so when it is empty the typed text will be at its center.

Actually I just noticed that even when setting the textContainerInset to the fixed value of what I know to be half the size of the textview height in UITextView.didMoveToWindow(), the problem still appears.

Detecting UITextView size change in order to set its textContainerInset
 
 
Q