Multiple annotation callouts displaying in MKMapView

后端 未结 3 1236
醉话见心
醉话见心 2020-11-27 23:05

Is it possible to open simultaneously more then one callout?

The code:

- (void)mapViewDidFinishLoadingMap:(MKMapView *)theMapView {
    for (id

        
3条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 23:33

    From a strict API perspective, this does not seem possible.

    The -(void)setSelected:(BOOL)selected animated:(BOOL)animated selector on MKAnnotationView states : "You should not call this method directly. An MKMapView object calls this method in response to user interactions with the annotation." so the underlying message is that the selection of annotationView instances in under the full responsability of user selection, and as the user can only select one of them at a time, you shouldn't be able to get several of them selected at the same time.

    Even if the documentation says that should not call this method directly, did you try to invoke it anyway with setSelected:YES on several MKAnnotationView instances to see what it gives ?

    THE CLEAN WAY I WOULD DO IT : (not tested myself however)

    • don't rely on the selection mechanism of the MKMapView
    • subclass the MKAnnotationView to implement a custom one
    • do the customization in such a way that the callout is part of the annotation view so that you can display several of them.

    If you do it like this, you can make appear several callout bubble at the same time and get something that would look like :

    alt text http://a1.phobos.apple.com/us/r1000/048/Purple/2b/b2/ec/mzl.ttcsrlee.480x480-75.jpg

提交回复
热议问题