Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView: Cancel opening a link when "touch up" is outside of the link?

I have a UIWebView with links in the text which open Safari if pressed.

If a user touches a link, it darkens...but if he wants to cancel pressing the link by moving his finger away first, it stays dark, and releasing the finger anywhere opens the link.

Is there some way to enable the user to "cancel" his "click" by moving away his finger - along the lines of the behavior of a "touch up inside" button?

like image 845
Epaga Avatar asked Mar 18 '11 11:03

Epaga


1 Answers

There's no way of doing exactly what you asked using the public SDK.
The best answer I can think of is to track touch began and touch ended events for the UIWebView itself. Then, add a UIWebviewDelegate, and to this delegate's interface, add a boolean bLastTouchDidWander (name is purely for example)

On a touch Down, you set bLastTouchDidWander to false.

On a touch UP, you measure how far the touch moved. If it moved more than a set amount, consider this a "touch up outside", and set bLasTTouchDidWander to true.

Then ,for the webView:shouldStartLoadWithRequest:navigationType: message of the UIWebViewDelegate, if bLastTouchDidWander is true, don't follow the link.

like image 50
Jordaan Mylonas Avatar answered Nov 14 '22 14:11

Jordaan Mylonas