views:

287

answers:

2

Hi,

How to send touch events from uiview to uiwebview without using undocumented methods ?

My problem is to hide/show the tabbar and navigation bar when the user touches the uiwebview. this actually needs customization of uiwebview which is not adviced. I am planning to put a transparent view on top of the uiwebview and then recieve the touch events from there, use them and then send it to uiwebview. For this i want to know how to send the touch events to webview from view.

A: 

This seems to be impossible. You can capture touch events with a custom overlay, but invoking your own UITouch events is not possible, nor is it possible to change the target view of an existing UITouch object.

In other words: as soon as a finger hits the screen, the touch event created contains the target. After that it is carved in stone and the webview will never respond to it. (someone please prove me wrong!)

The next best thing then - which I don't recommend - is to determine if the page is being scrolled, waiting for

[[browser stringByEvaluatingJavaScriptFromString:@"scrollY+scrollX"] intValue];

to become nonzero, in a loop. Javascript evaluation seems a bit slow; at least you can't do this 10 times per second.

mvds
A: 

This is totally possible. You need to subclass the UIView that contains the UIWebView, or the UIWindow, and then relay the touch event. Refer to this post.

William