开发者

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开发者_如何学JAVA 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜