Reputation: 1296
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?
Upvotes: 0
Views: 1050
Reputation: 6058
In iOS 5, the UIWebView
has a scrollView
property which is the UIScrollView
responsible for handling the scrolling. Prior to iOS 5 you can search the UIWebView
'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 the scrollViewDidScroll:
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 intercepted UIScrollViewDelegate
methods to the UIWebView
too. To do this, you can call the UIWebView at the end of all mandatory methods within the protocol and implement something like forwardInvocation:
or forwardingTargetForSelector
for the optional protocol methods. This will preserve your original UIWebView
behavior and allow you to enhance it with your own logic.
Upvotes: 1
Reputation: 6064
Why can't you just put the header as a separate view above the UIWebView
? Why does it have to be a subview?
Upvotes: 0