I have subclassed UIScrollView and I have two instances of MyScrollView each in their own view controller, with a segmented controller to switch between them. Both view controllers are added as child controllers in a main container view. They are switched by simply hiding/unhiding the view controller views, and calling the view appearance/disappearance methods on each controller at the correct time.
All of the above has been working fine for a couple of months. Nothing is unloaded in order to maintain state and responsiveness when switching.
My problem is quite a subtle one, illustrated as such:-
- launch app
- load view controller A into container view, which loads MyScrollView instance 1
- tap segmented controller
- hide view controller A's view
- load view controller B into container view, which loads MyScrollView instance 2
- tap segmented controller
- hide view controller B's view
show view controller A, which shows MyScrollView instance 1
Now, when I scroll any instance of MyScrollView, it stops sharply without decelerating.
When I hook up the delegate and add breakpoints, I see that scrollViewWillEndDragging:withVelocity:targetContentOffset: is called as expected, but the next call to scrollViewDidEndDragging:willDecelerate: has the decelerate argument as NO. Checking back, it was YES on the first two instances (i.e. when the scrollviews were freshly loaded).
This appears to be a "sticky" bug - once it has happened, it will not go away until I reload the scrollview. It happens to both scrollviews (they are the same class), and it seems to be to do with being shown twice. On the second showing, the scrolling will no longer decelerate.
I've tried setting all the appropriate properties on the scroll view each time its shown; I've tried different delegate objects; I've checked the contentSize is not changing dynamically, and that the scroll views are not being updated in any way during the scroll.
I haven't posted any code since this is a large project, and in any case there's no obvious focal point to the problem. If anyone can suggest a part they'd like to see, I can post that.
EDIT
I just tried removing the scrollview from view controller B, and the problem still exists. Therefore it looks like it's the act of hiding/showing MyScrollView that causes the problem, rather than any interaction between the two scroll views or their delegates.