理想情况下,有一种方法可以在 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/