Hi all, I am developing an application for iphone which loads some information to webview.I used hittest delegate to catch the touch ,Now i need to find the direction of touch movement.Is there any way to find this...Thanks in advance
You could try subclassing UIWebView
and override the touchesBegan
and touchesMoved
etc. methods.
I'm not sure what "used hittest delegate" means, but I think what you need to do is catch the touches like @MrMage was saying. However you should not need to subclass UIWebView to do this.
UIResponder exposes the following:
– touchesBegan:withEvent:
– touchesMoved:withEvent:
– touchesEnded:withEvent:
– touchesCancelled:withEvent:
You should be able to have your own UIView subclass, as the superview of your UIWebView in interface builder. Listen for these events, and confirm they are raised to you, it sounds like you are familiar with Interface Builder, so I won't go into that.
To "find the direction of touch movement" is a little vague. I'm guessing you want to detect if the swipe has gone "up" or "down" or "left" or "right" from the start point to the end point. You can do this very easily by comparing the touch at touchesBegan touch and the touchesEnded touch coordinates.
Something like this should work:
if ((endTouch.x - startTouch.x) > 0) { NSLog(@"swipe right"); }
else if ((endTouch.x - startTouch.x) < 0) { NSLog(@"swipe left"); }
Remember, for any given touch, a UITouch instance is created, and that memory address does not change. In this way you can safely compare addresses of UITouch to ensure you are tracking the same one, which is very useful when there are multiple touches (like the NSSet you are getting on the touch events). The Event Handling Guide is a great resource.