简体   繁体   English

如何检测用户何时将手指放在UIWebView中的图像上?

[英]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.

相关问题 当我的手指移动时,如何填充图像的透明区域 - how can i fill the transparent area of the image when my finger moved on 如何创建当用户在iPhone上滑动手指时激活的按钮 - How to create buttons which are activated when the user slides their finger over them on iPhone 如何检测用户何时刷过可编辑的UITableViewCell? - How can I detect when the user has swiped an editable UITableViewCell? 如何使用JavaScript在Mobile Safari(iphone)VS UIWebView(WebKit)上检测到用户? - can I detect a user on Mobile Safari (iphone) VS UIWebView (WebKit) with javascript? 检测iPhone SDK中手指滑过的视图 - Detect view that finger slid over in iPhone SDK 我如何感觉到用户在移动时将手指按住在屏幕上? - How can I sense the user is holding down their finger on the screen without moving? 如何通过手指获取UIScrollView分页? - How can I get UIScrollView paging by finger? 在电晕中将手指滑过对象时如何找到角度 - How to find the angle when finger is swiped over an object in corona Iphone-Web,jQuery:当用户在滑块上滑动手指时,如何使网页上的滑块滑动? - Iphone-web, jQuery: How can i make slider on web page to slide as the user slides finger on slider? 我怎么知道UIWebView中何时出现放大镜? - How can I know when the Magnifying Glass comes up in UIWebView?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM