user945620
user945620

Reputation:

UIWebView: How to tell when part of the HTML is visible?

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.

Upvotes: 0

Views: 283

Answers (1)

Oscar Gomez
Oscar Gomez

Reputation: 18488

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;

Upvotes: 1

Related Questions