Reputation: 561
so this question is not about a specific problem, but a general coding question.
Until now, I often used viewDidLayoutSubviews
to set a new contentInset for my UIScrollViews
. The reason is simple, in viewDidLayoutSubviews
self.topLayoutGuide.length
is set correctly, when e.g. rotating.
But today I wondered:
Why not set the contentInset
in viewWillLayoutSubviews
, shouldn't it be safer to do so there?
The reason why I wondered is:
Shouldn't it be better to set the contentInset
before laying out the UIScrollView
than setting it afterwards? The automatic scrolling for example may behave better if doing it this way?
Maybe I'm just overthinking all this.
What do you think about this?
Upvotes: 0
Views: 498
Reputation: 4351
Can you just set self.automaticallyAdjustsScrollViewInsets = YES
inside your view controller and let the system take care of it for you, or do you need some kind of custom insets?
EDIT
I'm not sure it makes a difference, although it's difficult to know for sure without trying it. As you're just adjusting the insets, it actually should really matter if it's set before or after the layout pass is done, as it doesn't change any of your constraints or trigger another layout pass. Unless you're noticing a particular issue with scrolling on rotation, I wouldn't worry about it too much.
Upvotes: 1