View Full Version : Handle touch on MKMapView
inverted
Jul 3, 2009, 10:36 AM
hey
i am using an MKMapView. i initialize it directly from the code.
when i touch an annotation on the map i 'move' (transfer) another view above the MKMapView to show to the user some details about the annotation.
now my question, how do i handle a touch somewhere else on the map ? cause in this case i want to close the details view again.
thank you for your help !
Jeremy1026
Jul 3, 2009, 10:45 AM
Hi Jeremy,
All you need to do is subclass MKMapView and override selectAnnotation:animated: as follows:
@implementation MyMapView
- (void)selectAnnotation:(id <MKAnnotation>)annotation animated:(BOOL)animated {
[super selectAnnotation:annotation animated:animated];
NSLog(@"%s", __FUNCTION__);
// do whatever you want with the annotation here...
}
@end
Wil Turner
Apple Developer Technical Support
UIKit • Core Data • Performance
That will tell you when an annotation is selected. Too bad I couldn't even get the sample code to work :confused:. If you get it to work please post your code.
inverted
Jul 3, 2009, 11:06 AM
hi, i was able to handle the "select"-event. for that i made my own subclass from "MKAnnotationView" and overwrote the - (void)setSelected:(BOOL)selected animated:(BOOL)animated; method.
but the way you showed me is much better. you don't mess up with the responsibility.
but i am looking for a solution to do the opposite :) i have to handle a touch inside the map, and not on an annotation.
i need that to hide my detailsView.
thanks
inverted
Jul 3, 2009, 11:11 AM
haha sometimes i could kick myself !
i found the answer :
@interface FriendAnnotationView : MKAnnotationView {
....
- (void)setSelected: (BOOL)selected animated: (BOOL)animated{
if(selected){
[self.delegate showDetailsToFriend];
}
else{
[self.delegate hideDetailsToFriend];
}
[super setSelected:selected animated:animated];
}
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.