Search code examples
iosmapkitmkannotationview

MKAnnotation Left / Right Accessory View Misplacement


Cannot figure out why this occurs. When my Title and Subtitle text is to long, I get the expected ... at the end of the text. However my left and right accessory views get messed up like this.

enter image description here

The accessory view frame and bounds have not changed. They are the same as when the views are drawn normally. Like,

enter image description here

Either the Title can be long or the subtile can be long, and the views are not misplaced. Only when both are long and have the trailing ... do they get messed up.

Cannot find any documentation about what the max size of the view / or text length etc should be.

I've resorted to a hack of counting the string length and when they exceed my limit I print out a short title or subtitle. I'd rather leave it as it and just figure out why those views get pushed up and how to fix.

Thanks

Note: Im use the default MKAnnotationView, just setting the title and subtitle.


Solution

  • This seems to be a bug which can be workarounded in different ways.

    The rightCalloutAccessoryView vertical alignment can be fixed by simply setting the autoresizingMask as follows:

    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
    
    rightButton.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
    annotationView.rightCalloutAccessoryView = rightButton;
    

    The same trick does not work with the leftCalloutAccessoryView which apparently has an bug with how NSLayoutAttributes are setup by default. In this case the easiest (ugliest) and only fix I found is to hard code the height of the view you assign to leftCalloutAccessoryView: 54px on iOS8, 45px on iOS7.