MapView Annotation not dragging

后端 未结 4 1710
渐次进展
渐次进展 2021-01-13 13:46

I am trying to implement a draggable \"pin\" (actually a custom icon) in a map view. This is the delegate code that I have:

  -(MKAnnotationView *) mapView:(         


        
4条回答
  •  盖世英雄少女心
    2021-01-13 14:36

    This is a tricky one! I've just implemented something similar (though I subclassed MKAnnotationView) and when I tried adding the annotationView:didChange delegate method to my view controller it didn't get called even though I was able to drag the annotation view??

    I also copy/pasted your code into my view controller and it worked straight out of the box, with the delegate method being called and all!

    The only thing I can think of is that instead of passing mvMap to dequeueReusableAnnotationViewWithIdentifier: try passing the mapView object that is supplied by the delegate method. Based on the code you provided above I am unable to tell if they are the same object so it might be worth a shot?

    aView=(MKAnnotationView *) [mvMap dequeueReusableAnnotationViewWithIdentifier:annotation.title];
    

    [EDIT TO ADD MY CODE AS REFERENCE]

    - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id)annotation
    {
        static NSString* ParkAnnotationIdentifier = @"ParkAnnotationIdentifier";
        MKAnnotationView* parkAnnotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:ParkAnnotationIdentifier];
        if (!parkAnnotationView)
        {
            MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
                                                                             reuseIdentifier:ParkAnnotationIdentifier] autorelease];
            UIImage *imageIcon = [UIImage imageNamed:@"scooterIcon.png"];
            annotationView.image = imageIcon;
            annotationView.draggable = YES;
            return annotationView;
        }
        else
        {
            parkAnnotationView.annotation = annotation;
        }
        return parkAnnotationView;
    }
    

提交回复
热议问题