【发布时间】:2015-03-25 20:45:09
【问题描述】:
我有一些带有标题和副标题的注释;其他只有头衔的人。当我以编程方式选择注释时,我经常会看到尺寸不正确的标注(例如,对于文本来说通常太高)。通常情况下,看起来大小可以容纳字幕的视图用于仅带有标题的注释。这些标注都没有附件视图。有没有人遇到过这个问题?我显然需要强制每个附件视图在获取新内容时自行调整大小,但不知道该怎么做。
【问题讨论】:
我有一些带有标题和副标题的注释;其他只有头衔的人。当我以编程方式选择注释时,我经常会看到尺寸不正确的标注(例如,对于文本来说通常太高)。通常情况下,看起来大小可以容纳字幕的视图用于仅带有标题的注释。这些标注都没有附件视图。有没有人遇到过这个问题?我显然需要强制每个附件视图在获取新内容时自行调整大小,但不知道该怎么做。
【问题讨论】:
由于我在您的问题中没有看到任何代码,但我认为我很久以前编写的以下代码可能会回答您的问题。
MKAnnotationView *annotationView = [self.mapView viewForAnnotation:annotation];
// The annotation must be visible, otherwise a refresh isn't needed
if (annotationView != nil) {
NSArray *selectedAnnotations = self.mapView.selectedAnnotations;
// The annotation must be selected, otherwise a refresh isn't needed
if ((selectedAnnotations != nil) && ([self.mapView.selectedAnnotations indexOfObject:annotation] != NSNotFound)) {
// Unset and re-set the right button to force relayout
UIView *view = annotationView.rightCalloutAccessoryView;
annotationView.rightCalloutAccessoryView = nil;
annotationView.rightCalloutAccessoryView = view;
}
}
【讨论】: