I have a weird issue with MKMapView
's callout view. I am using leftCalloutAccessoryView
to set up a view that holds an image and a couple of labels as shown in the picture below. Whenever I tap the annotation, the animation that normally shows the callout appears and then the my content disappears and reappears by sliding from the left side as shown in the gif image. I don't know how to fix this. This only happens on iOS 8. It appears fine on iOS 7.
I figured it out myself. So I'm just posting this to help anyone running into the same problem. The problem was with how I was returning the leftCalloutAccessoryView
. I was overriding the method and returning a UIView
by allocating it there. That was for some reason causing the animation. I created a new property and initialized the accessory view and returned the same object in leftCalloutAccessoryView
every time. That fixed the problem.
@property (nonatomic, strong) UIView *accessory;
and
-(UIView *)leftCalloutAccessoryView {
return self.accessory;
}
-(UIView *)accessory {
if (_accessory == nil) {
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.mapView.frame.size.width-8, height)];
// custom code here
_accessory = backgroundView;
}
return _accessory;
}
Doing all this fixed the problem.