質問

I want to create custom MKAnnotationView (with image) without a callout, but expandable after touch. Here is what i have in mind:

1) First the MKAnnotation looks like this:

enter image description here

2) Then after tap on it this should expand and looks like this:

enter image description here

I've started with customing MKAnnotationView and have a class:

@interface CustomPinAnnotation : NSObject <MKAnnotation>

The class have method:

-(MKAnnotationView*)annotationView {
    MKAnnotationView *annotationView = [[MKAnnotationView alloc] initWithAnnotation:self reuseIdentifier:@"AnnotationIdentifier"];
    annotationView.enabled = YES;
    annotationView.image = [[UIImage imageNamed:@"star"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

    return annotationView;
}

And what i try to do is set a customView as a subview to the MKAnnotationView, but when i don't set The image it will not responding (this is pretty logical after i've think about it), but got the feeling that I'm doing something very nasty here, and should be a way to override MKAnnotationView somehow.

役に立ちましたか?

解決

 -(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
   {
          enemyAnnotationView.image = [UIImage imageNamed:@"firstImage.png"];
   }

 -(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
   {
          enemyAnnotationView.image = [UIImage imageNamed:@"SecondImage.png"];
   }

Try like this first method is for the View for annotation that time your first image will be appears,

Second method will run when user select annotation

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top