Z-index of iOS MapKit user location annotation

后端 未结 9 2316
天命终不由人
天命终不由人 2020-12-13 07:12

I need to draw the current user annotation (the blue dot) on top of all other annotations. Right now it is getting drawn underneath my other annotations and getting hidden.

9条回答
  •  醉话见心
    2020-12-13 07:20

    Here is a way to do it using predicates. I think it should be faster

    NSPredicate *userLocationPredicate = [NSPredicate predicateWithFormat:@"class == %@", [MKUserLocation class]];
    NSArray* userLocation = [[self.mapView annotations] filteredArrayUsingPredicate:userLocationPredicate];
    
    if([userLocation count]) {
        NSLog(@"Bring blue location dot to front");
        MKAnnotationView *view = [self.mapView viewForAnnotation:(MKUserLocation *)[userLocation objectAtIndex:0]];
        [[view superview] bringSubviewToFront:view];
    }
    

提交回复
热议问题