通过触摸传递到 UIWebView 的一部分 [英] Pass through touches to portion of UIWebView
问题描述
我有一个 UIWebView.使用这样的东西:
I have a UIWebView. Using something like this:
http://blog.evandavey.com/2009/02/how-to-make-uiwebview-transparent.html
.. 我已经让 UIWebView 透明了.我现在需要能够将 webview 上的触摸传递到下面的视图,但只能传递到 web 视图的矩形部分.
.. I have made the UIWebView transparent. I now need to be able to pass though touches on the webview to the view below, but only on a rectangular portion of the web view.
所以,假设 webview 是一个正方形,它的中心有一个正方形区域,必须通过触摸到下面的视图.
So, imagine the webview is a square, and it has a square area in the centre which must pass-thru touches to the view below.
有没有办法做到这一点?
Is there a way to do this?
推荐答案
这是一种更具体的 hitTest
操作形式.
This is a more specific form of hitTest
manipulation.
首先,创建一个UIView
的子类.我打电话给我的 ViewWithHole
.
First, create a subclass of UIView
. I called mine ViewWithHole
.
在其标题中,为 UIView
定义一个属性,该属性将作为外部视图的孔.将其设为 IBOutlet
.
In its header, define a property for a UIView
that will be the hole through the outer view. Make this an IBOutlet
.
@property (retain) IBOutlet UIView *holeView;
然后覆盖hitTest
.如果该点在孔内返回命中,则返回该命中.否则返回通常会返回的内容.
Then override hitTest
. If the point is returns a hit within the hole, return that. Otherwise return what it usually would.
- (UIView*) hitTest:(CGPoint)point withEvent:(UIEvent *)event;
{
CGPoint pointInHole = [self convertPoint:point toView:self.holeView];
UIView *viewInHole = [self.holeView hitTest:pointInHole withEvent:event];
if (viewInHole)
return viewInHole;
else
return [super hitTest:point withEvent:event];
}
在 Interface Builder 中,或以编程方式,放置一个 ViewWithHole
.按此顺序将 UIView
和 UIWebView
放入其中.使 UIView
成为 ViewWithHole
的 holeView
.
In Interface Builder, or programmatically, place a ViewWithHole
. Put a UIView
and a UIWebView
within it, in that order. Make the UIView
the holeView
of the ViewWithHole
.
holeView
本身可以是交互式的,或者您可以在其中放置任意数量的交互式视图.在这里,我在其中放置了一些标准视图以确保它们有效.洞内的任何点击都将被发送到它及其子视图,而不是顶部的 UIWebView
.holeView
之外的任何点击都将像往常一样被 UIWebView
接收.
The holeView
can itself be interactive, or you can put any number of interactive views within it. Here, I put a few standard views in there to make sure they work. Any taps on within the hole will be sent to it and its subviews, not the UIWebView
on top. Any taps outside the holeView
will be received by the UIWebView
as usual.
您可以在洞前显示任意数量和类型的视图;重要的是 holeView
已正确连接.
You can have any number and type of views displayed in front of the hole; all that matters is that the holeView
is properly connected.
这篇关于通过触摸传递到 UIWebView 的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!