开发者

When I set the delegate of a UIWebView's built-in UIScrollView, I lose the ability to pinch to zoom, how can I get it back?

I am using a UIWebView to show a PDF. I need to track some UIScrollView events, so I set the built-in UIScrollView like this:

for(UIScrollView *s in webView.subviews) {

    s.delegate = self;

}

But the problem is that when I do this, I lose the ability to pinch to zoom (like I could before because the UIWebView's Scale Pages to Fit property was set). How come this happens? What can I do to fix it? I went ahead and implemented the UIScrollView shouldZoom method, but when I pass back the scrollView as the view to zoom on, it zooms from the corner, not where my fingers are.

D开发者_运维技巧oes anybody know a solution to this problem? How can I have the UIScrollView delegate set, and still retain natural zooming ability?

Thanks!


You are messing with some UIWebView internals. This feels like a bad hack, but I think you could forward all the UIScrollViewDelegate methods back to UIWebView in addition to doing whatever you need to do.

Also, UIWebView has many subviews. You should check and override the delegate just for the UIScrollView.

for (UIView *subview in webViews.subviews) {
    if ([subview isKindOfClass:[UIScrollView class]]) {
        subview.delegate = self;
    }
}


Either handle the following events in your delegate:

– viewForZoomingInScrollView:
– scrollViewWillBeginZooming:withView:
– scrollViewDidEndZooming:withView:atScale:
– scrollViewDidZoom:

or save the original delegate

origDelegate = s.delegate;
s.delegate = self;

and forward the calls, e.g:

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
    return [origDelegate viewForZoomingInScrollView:scrollView]; 
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜