0

Is there a callback offered by UIWebView that is called when scrolling occurs, and if so, how can I get the current content offset?

Thanks.

1 Answers1

1

You can using this property available in ios 5.0:

@property(nonatomic, readonly, retain) UIScrollView *scrollView

Or prior to iOS 5.0:

NSArray *subViews = [NSArray arrayWithArray:[myWebview subviews]];
UIScrollView *webScroller = (UIScrollView *)[subViews objectAtIndex:0];

You can then implement the UIScrollViewProtocol and do something like this:

UIScrollView *webScrollView = myWebView.scrollView;
webScrollView.delegate = self;

//implement method from delegate..

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //Scrolled
}

To get the contentOffset all you have to do is:

CGPoint offSet = webScrollView.contentOffset;
Oscar Gomez
  • 18,436
  • 13
  • 85
  • 118
  • Wait, are you serious? With UIScrollView I've used scrollViewDidScroll. Why would that not work in iOS 4.x? –  Oct 21 '11 at 23:18
  • @Mithras What is new is the property in UIWebView :). See my updated answer on how to get a reference to the scrollView before 5.0. – Oscar Gomez Oct 21 '11 at 23:20
  • Yep, that's what I was planning to do. Thanks. –  Oct 22 '11 at 12:19