[英]How can I detect when a user holds their finger over an image in a UIWebView?
In Mobile Safari, if you hold your finger over an image for a second or two, a little popup appears giving you the option of saving or copying the image. 在Mobile Safari中,如果将手指放在图像上一两秒钟,则会出现一个小弹出窗口,您可以选择保存或复制图像。
Is there any way to do this in a UIWebView in an app? 有没有办法在应用程序的UIWebView中执行此操作? Gesture recognizers seem to be ignored and I don't see any way to hook into that behavior.
手势识别器似乎被忽略了,我看不出有任何方法可以陷入这种行为。
I am not very strong in web dev, but i am pretty shure you should use custom java script code which will detect the click on image and call the popup to appear. 我在网络开发人员方面不是很坚强,但是我很确定您应该使用自定义Java脚本代码 ,该代码将检测图像上的点击并调用弹出窗口来显示。
Here is just an example how simple js injection works in iOS UiWebView. 这只是一个示例,说明简单的js注入如何在iOS UiWebView中工作。
There are javascript events you can hook into to get the effect you want 您可以加入一些JavaScript事件以获得所需的效果
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[webView stringByEvaluatingJavaScriptFromString:@"window.ontouchstart=function(/* ... */);"];
}
Put your custom code in ontouchstart. 将您的自定义代码放入ontouchstart。 I'd imagine what you want is a timer that checks if the user releases the touch before x milliseconds, and if that doesn't happen, you can call an obj-c function from javascript to activate the popup.
我可以想象您想要的是一个计时器,该计时器检查用户是否在x毫秒之前释放触摸,如果没有发生,则可以从javascript调用obj-c函数来激活弹出窗口。 Get the coords of the touch event and compare them to the coords of all the images in your page.
获取触摸事件的坐标,并将其与页面中所有图像的坐标进行比较。
I'm hoping someone will know of a native way to do this though; 我希望有人会知道这样做的本机方法。 this is a really hackish workaround.
这是一个非常骇人的解决方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.