Search code examples
iphoneiosmapkitmkmapviewmkannotationview

Update AnnotationView after/during zoom


I need to change the centerOffset property of an AnnotationView when the zoomlevel changed. I don't want to remove and add the Annotations again.

So how can I access and update the AnnotationViews after zooming?

Any ideas on this?

Best Regards, Christian


Solution

  • One solution would be to use these MKMapView methods :

    - (NSSet *)annotationsInMapRect:(MKMapRect)mapRect // iOS4.2+ only!
    

    to retrieve visible Annotations, then use :

    - (MKAnnotationView *)viewForAnnotation:(id<MKAnnotation>)annotation;
    

    To get the corresponding view (should never return nil if first function does it job correctly)

    Then I guess changing centerOffset should do the job, (plus maybe some -[UIView setNeedsDisplay/Layout] to force a redraw)

    Changing centerOffset depending on zoomLevel sounds strange, but I guess you have your reasons :)