javascript:可以使用 touchmove 来模拟 iPhone 上的鼠标悬停吗?

标签 javascript iphone ipad mouseover

理想情况下,有一种方法可以在 iphone/ipad 上使用 touchstart 和 touchmove 来模拟以下 javascript 的鼠标悬停图像映射功能:

http://www.netzgesta.de/mapper/

我希望允许 iphone/ipad 用户触摸 map ,突出显示他们触摸过的国家/地区,当他们将手指拖动到其他国家/地区时,这些国家/地区会依次亮起,就像通过桌面一样使用鼠标悬停的浏览器。

想法,想法?这可能吗?

最佳答案

您可以尝试使用touchesBegan和touchesMoved来获取触摸的坐标,然后检查它们是否在 map 上的对象内。要获取这些坐标,请使用:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint touchedPoint = [touch locationInView:self.view];
    //now you can use touchedPoint.x and touchedPoint.y for the coordiantes of the touched point.
}

同样,您可以使用

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    CGPoint touchedPoint = [touch locationInView:self.view];
}

还存在touchesEnded和touchesCancelled。您可以使用这些来获取触摸的坐标,然后由您来解释这些点。您可以为要滚动的每个部分绘制近似矩形,这将使这变得相当简单,但是如果您有一个具有 javascript map 的预期功能的 map ,您将需要更复杂的形状,并且必须使用其他方法来定义形状.

关于javascript:可以使用 touchmove 来模拟 iPhone 上的鼠标悬停吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7407028/

相关文章:

javascript - 访问数组中的某个对象

javascript - 设置 body 展示风格无与一个 child 展示风格 block

javascript - 如何使静态网站的内容可共享

iphone - 应用程序不在设备上运行 - 如果不使用 self.attribute,我无法从其子类调用属性的类

iphone - SDWebImage 操作未被取消

objective-c - 未调用 UITableViewController init 方法

ipad - 在 iPad 上播放音频

javascript - 重新加载es6类

css - iPad 联系链接 CSS 覆盖

iphone - 如何使用 iOS 的库和 TWRequest 获取刚刚发布的推文?