UIWebView 是否提供了在滚动发生时调用的回调,如果是,我如何获取当前的内容偏移量?
谢谢。
您可以使用 ios 5.0 中提供的此属性:
@property(nonatomic, readonly, retain) UIScrollView *scrollView
或在 iOS 5.0 之前:
NSArray *subViews = [NSArray arrayWithArray:[myWebview subviews]];
UIScrollView *webScroller = (UIScrollView *)[subViews objectAtIndex:0];
然后,您可以实现UIScrollViewProtocol
并执行以下操作:
UIScrollView *webScrollView = myWebView.scrollView;
webScrollView.delegate = self;
//implement method from delegate..
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
//Scrolled
}
要获得 contentOffset,您所要做的就是:
CGPoint offSet = webScrollView.contentOffset;