Iphone – Swipe functionality on UIwebview iPhone development –


I'd like to capture user's swipe event for my iPhone application.

as per apple, It can be easily get it from touchesMoved:withEvent:.

I have UIView which contains navigationbar on the top, toolbar at bottom, in between it has uiwebView.

Now when user swipes i want to capture this event, but i am not able to get user's touch event for UIwebView.

I have my touchesMoved event in my viewcontroller, Where do i write this touch?

Please help me..

Best Solution

You could subclass UIWebView, only overwriting the touchesMoved, touchesStarted, touchesEnded, and touchesCancelled methods. Do your swipe detection in those methods, and have them call [super ...] if the call does not belong to a swipe.

The problem here might be that detecting the swipe does not prevent the default behavior of the UIWebView. The super class also needs to know when touches start, move, end, or cancel. This way it's able to perform the right selector on the delegate.

So when you overwrite those methods and do not call [super ...], or only if it's not a swipe, the behavior of UIWebView itself is probably undefined. That's why I mentioned you should always call [super ...] in your own implementation.

Edit: SO did not like me putting strings between less-then and greater-then brackets. So in the above, wherever I mentioned [super ...], please fill in touchesStarted, touchesMoved, touchesEnded, and touchesCancelled on the dots ....