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.
精彩评论