How would one get the contentOffset or similar information about a UIScrollView while the user is still scrolling? For example if I wanted to place an image as a header right above the content of a UIWebView, without the image being part of the WebView’s scrollView, but have it update while the user scrolls, not just jumping to the position after they let go. How could I go about doing this?
How would one get the contentOffset or similar information about a UIScrollView while the
Share
In iOS 5, the
UIWebViewhas ascrollViewproperty which is theUIScrollViewresponsible for handling the scrolling. Prior to iOS 5 you can search theUIWebView‘s subviews property for the subview using[subview isKindOfClass:[UIScrollView class]].Once you have the
UIScrollView, you can then set its delegate property. In the delegate you can then respond to thescrollViewDidScroll:message when the user scrolls, and update the position/contents of your header view.Added: 29/2/2012 – In order to preserve the
UIWebView‘s functionality, you will need to forward your interceptedUIScrollViewDelegatemethods to theUIWebViewtoo. To do this, you can call the UIWebView at the end of all mandatory methods within the protocol and implement something likeforwardInvocation:orforwardingTargetForSelectorfor the optional protocol methods. This will preserve your originalUIWebViewbehavior and allow you to enhance it with your own logic.