开发者

javascript: possible to use touchmove to mimic mouseover on iphone?

Ideally there is a way to mimic the mouseover imagemap capabilities of the following javascript using touchstart and touchmove on the iphone/ipad:

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

I wish to allow the iphone/ipad user to touch the map, have the country they've touched highli开发者_如何学Pythonght, and when they drag their finger over other countries, those countries in turn light up, just as they would via a desktop browser using mouseover.

Ideas, thoughts? Is this even possible?


You might try using touchesBegan and touchesMoved to get the coordinates of your touch and then check to see if those are within the object on your map. To get these coordinates, use:

- (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.
}

Similarly, you can use

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

There also exists touchesEnded and touchesCancelled. You can use these to get the coordinates of the touch, afterwards it is up to you to interpret these points. You could approximate rectangles for each section to be rolled over which would make this rather simple, but if you have a map with the intended functionality as the javascript map, you would need more complex shapes and would have to use other methods to define the shape.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜