Domanda

What I wish to do is to fade-in and fade-out some custom annotation views. In order to do this I need to have the pointers to those views. Have been thinking of collecting these pointers in mapView:viewForAnnotation. But I am not sure if this is the right way.

The reason is since annotation views are set up to be recycled, I worry that they can be detached from their annotations once they are moved out of the screen. So my thinking is, view pointers collected in mapView:viewForAnnotation, may not be reliable since we don't know if they are still on the screen or not.

Hope somebody can suggest a proper way to keep track of these view pointers. Or suggest some other standard or reliable way of fading in and out the annotation views.

Update :

Just found out that viewForAnnotation does work. And I don't really need to keep track of the annotations (at least in this case) if they are on screen or not.

È stato utile?

Soluzione

Try this where you get to the zoom that you want to animate the annotationViews:

for (MyAnnotation *annotation in myMapView.annotations)
{
    MKAnnotationView *annotationView = [myMapView viewForAnnotation:annotation];
    //Do your animation to the annotationView
    //Example for fadeOut - fadeIn
    [UIView animateWithDuration:0.5 animations:^{
        annotationView.alpha = 0.2;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.5 animations:^{
            annotationView.alpha = 1;
        }];
    }];
}

If you have all kinds of annotationView types and you want to animate just part of them, then you will need to check the type before the animation.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top