I want to scroll to the top of a UIScrollView
. You have two possibilities:
setContentOffset()
scrollView.contentOffset
If I use an animation then the scrollview sometimes scrolls to (0, -26)
instead of (0, 0)
. So it scrolls further but then doesn't go back to (0, 0)
. This currently happens on iPad only.
If I don't use an animation this works everytime as expected. Has somebody a clue what is wrong here? I tested this on iPad 2 iOS 8.4 simulator
Edit:
Before I made my call with setContentOffset()
I had this:
scrollView.layoutIfNeeded();
scrollView.setContentOffset(somePosition, true);
Removing layoutIfNeeded
also removes the problem. But why?
Note: I wasn't calling setContentOffset()
multiple times consecutively. That are completely different tasks!