当我设置 UIWebView 内置 UIScrollView 的委托时,我失去了捏合缩放的能力,如何才能恢复它?

发布于 2024-11-19 20:42:14 字数 429 浏览 3 评论 0原文

我正在使用 UIWebView 来显示 PDF。我需要跟踪一些 UIScrollView 事件,所以我像这样设置内置 UIScrollView:

for(UIScrollView *s in webView.subviews) {

    s.delegate = self;

}

但问题是,当我这样做时,我失去了捏缩放的能力(就像以前一样,因为 UIWebView 的 Scale Pages to Fit 属性已设置)。怎么会出现这样的情况呢?我能做什么来修复它?我继续实现了 UIScrollView shouldZoom 方法,但是当我将scrollView作为要放大的视图传回时,它从角落缩放,而不是我手指所在的位置。

有人知道这个问题的解决方案吗?我怎样才能设置 UIScrollView 委托,并仍然保留自然缩放能力?

谢谢!

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.

Does anybody know a solution to this problem? How can I have the UIScrollView delegate set, and still retain natural zooming ability?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瀞厅☆埖开 2024-11-26 20:42:15

您正在搞乱一些 UIWebView 内部结构。这感觉像是一个糟糕的黑客,但我认为除了做任何您需要做的事情之外,您还可以将所有 UIScrollViewDelegate 方法转发回 UIWebView。

此外,UIWebView 有许多子视图。您应该仅检查并重写 UIScrollView 的委托。

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

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;
    }
}
惜醉颜 2024-11-26 20:42:15

在您的委托中处理以下事件:

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

或保存原始委托

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

并转发调用,例如:

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

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]; 
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文