简体   繁体   English

UIWebView:当“修饰”在链接之外时取消打开链接?

[英]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. 我有一个UIWebView,文本中有链接,如果按下则打开Safari。

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? 是否有某种方法可以让用户通过移开他的手指来“取消”他的“点击” - 沿着“内部触摸”按钮的行为?

There's no way of doing exactly what you asked using the public SDK. 无法使用公共SDK完全按照您的要求进行操作。
The best answer I can think of is to track touch began and touch ended events for the UIWebView itself. 我能想到的最佳答案是跟踪UIWebView本身的触摸开始和触摸结束事件。 Then, add a UIWebviewDelegate , and to this delegate's interface, add a boolean bLastTouchDidWander (name is purely for example) 然后,添加一个UIWebviewDelegate ,并在此委托的接口中添加一个布尔值bLastTouchDidWander (名称纯粹为例)

On a touch Down, you set bLastTouchDidWander to false. 触摸向下,将bLastTouchDidWander设置为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. 如果它移动超过设定的数量,请将其视为“外部bLasTTouchDidWander ”,并将bLasTTouchDidWander设置为true。

Then ,for the webView:shouldStartLoadWithRequest:navigationType: message of the UIWebViewDelegate , if bLastTouchDidWander is true, don't follow the link. 然后,对于webView:shouldStartLoadWithRequest:navigationType: UIWebViewDelegate消息,如果bLastTouchDidWander为true,则不要关注该链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM