I have a UIWebView. Using something like this:
http://blog.evandavey.com/2009/02/how-to-make-uiwebview-transparent.html
.. 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.
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?
my firsth idea is something like this:
this should work if the view below is stationary but you haven't given any information about the view below (if there's buttons, or if it moves..stuff like that) so ...yea..do that
This is a more specific form of
hitTest
manipulation.First, create a subclass of
UIView
. I called mineViewWithHole
.In its header, define a property for a
UIView
that will be the hole through the outer view. Make this anIBOutlet
.Then override
hitTest
. If the point is returns a hit within the hole, return that. Otherwise return what it usually would.In Interface Builder, or programmatically, place a
ViewWithHole
. Put aUIView
and aUIWebView
within it, in that order. Make theUIView
theholeView
of theViewWithHole
.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 theUIWebView
on top. Any taps outside theholeView
will be received by theUIWebView
as usual.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.I have another idea: get the global click. When someone click in iPhone, it send a message to global
sendEvent
. So you listen to it and do the task you want.To do this, you need to subclass the
UIApplication
. First, in main.c use this functionthen implement this class:
Now you listen this NSNotification and do all the checks: Is in the correct frame, has the correct UIView, etc, etc...
I think that there is a very easy solution to your problem... You do not specify it, but I deduce that you don't want the user to interact with the webview HTML. If that is so, just disable UserInteractionEnabled on the webview and the touches will pass trough.
Then you need your active view located in the center as you mentioned.
I hope it helps, if you need any clarification just comment it.
You could create a subclass of
UIWebView
and override itshitTest:withEvent:
andpointInside:withEvent:
to disregard the 'hole' - but Apple say you shouldn't subclass UIWebView.Or, you could create a UIView subclass and place the UIWebView within it as a subview, then make its
hitTest:withEvent:
method return views beneath the UIWebView.Here is a generic
hitTest
method for aUIView
subclass, that gives priority to any interactive subviews that aren't UIWebView, even if they're underneath the UIWebView. It doesn't have any specific 'hole' detection, buthitTest
is also where you want to do that. Just work out if thepoint
is in the hole before disregarding the UIWebView.