MKMapView,当我触摸pinview时如何添加自定义视图?

| MKMapView默认情况下,单击大头针视图时会出现带有小黑框的标题和副标题,但现在我想在视图上显示更多数据。当我单击大头针视图时,我想显示一个客户视图。 有人做过类似的事情吗?我尝试了以下方法,但是它们没有用:  使用对单击事件mapView的代理访问:didSelectAnnotationView,但委托仅支持ios4.x以上  使用tapgesture捕获事件,仅在ios3.2之后才支持  尝试继承MKMapView,发现无法获得触摸事件。     
已邀请:
具有自定义MKAnnotation的MKMapView也可能重复 这是创建自定义标注的方法 http://blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/ 想知道如何解决 \“ 3。尝试继承MKMapView,发现无法获得触摸事件。\”早于iOS4.x设备,这是如何 子类MKAnnotationView,如下所示(.h和.m文件) .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
然后在UIViewController for mapView中,您需要设置ClickableAnnotation委托和选择器 -(MKAnnotationView *)mapView:(MKMapView)mapViewParam viewForAnnotation:{id)annotation {     静态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

}
    

要回复问题请先登录注册