有没有人做过类似的事情?我尝试了以下方法,但它们不起作用:
答案 0 :(得分:-1)
也可能是MKMapView with custom MKAnnotation的副本 以下是创建自定义标注的方法 http://blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/
想知道如何解决 “3.尝试继承MKMapView,发现无法获得触摸事件。”早于iOS4.x设备,这里是如何
.h文件
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface ClickableMapAnnotationView : MKAnnotationView {
SEL pinClicked;
id delegate;
}
@property(nonatomic, assign) SEL pinClicked;
@property(nonatomic, assign) id delegate;
@end
.m文件
#import "ClickableMapAnnotationView.h"
@implementation ClickableMapAnnotationView
@synthesize pinClicked;
@synthesize delegate;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
if ( delegate != nil && [delegate respondsToSelector:pinClicked] )
[delegate performSelector:pinClicked withObject:self.annotation];
[super touchesBegan:touches withEvent:event];
}
@end
- (MKAnnotationView *)mapView:(MKMapView )mapViewParam viewForAnnotation:(id)annotation { static NSString PIN_RECYCLE_ID = @“pin”;
if ( annotation == self.mapView.userLocation) // this is my location pin, skip
return nil;
ClickableMapAnnotationView* pin = (ClickableMapAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier: PIN_RECYCLE_ID];
if ( pin == nil ) {
pin = [[[ClickableMapAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier: PIN_RECYCLE_ID] autorelease];
// wire, pin clicked functionality
pin.delegate = self;
pin.pinClicked = @selector(annotationViewClicked:);
...
-(void) annotationViewClicked:(id) sender {
// map pin has been clicked
}