总的来说,我仍然是iOS的新手,在测试我们的iOS 8兼容性时,我发现了一个问题。在iOS 7中,一切正常,但在iOS 8上,rightCalloutAccessoryView在某些情况下会出现偏差。
第一个屏幕截图:正确对齐

第二个屏幕截图:错误对齐

正如您所看到的,当InfoWindow有一个长标题时,问题就会发生。但在iOS 7上情况并非如此,我找不到任何提到这一点已经改变的东西?
我试着理解为什么,并找到解决这个问题的方法,但还是找不到任何东西。这是我们自己可以解决的,还是我们必须向苹果提交一个问题?
任何帮助/想法都将非常感谢,因为我在这个问题上不知何故遇到了太多的挑战。
添加MKAnnotationViews的代码
- (MKAnnotationView *)viewForStation:(id<MKAnnotation>)annotation {
static NSString *stationIdentifier = @"stao";
MKAnnotationView *annotationView = [self.mapView dequeueReusableAnnotationViewWithIdentifier:stationIdentifier];
if (annotationView == nil) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:stationIdentifier];
annotationView.image = [UIImage bundleImageNamed:PIN_IMAGE];
annotationView.canShowCallout = YES;
annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
return annotationView;
}您可能会感兴趣,我(刚才)也将这个问题添加到了apple.developer.com上的iOS 8测试版部分:https://devforums.apple.com/thread/242282?tstart=0
如果我在这里或在apple.developer.com上得到答案,我会反映它,这样我们就可以在这两个网站上找到它
发布于 2014-12-17 23:02:43
我通过设置自动调整大小的掩码来修复垂直bug和水平bug的frame.size.width解决了这个问题
UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton setFrame:CGRectMake(0, 0, CGRectGetWidth(infoButton.frame)+10, CGRectGetHeight(infoButton.frame))];
[infoButton setAutoresizingMask:UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleTopMargin];
[annotationView setRightCalloutAccessoryView:infoButton];发布于 2014-09-27 03:43:18
丑陋得要命,但我还是设法找到了解决这个问题的办法。
将附件视图高度设置为与详图索引视图高度相等的值。我使用了硬编码的值:
适用于iOS 7的
(您可能注意到,iOS 8中的默认注释标注视图的高度比iOS 7中的要大)。
在您的代码中,这将是:
- (MKAnnotationView *)viewForStation:(id<MKAnnotation>)annotation {
static NSString *stationIdentifier = @"stao";
MKAnnotationView *annotationView = [self.mapView dequeueReusableAnnotationViewWithIdentifier:stationIdentifier];
if (annotationView == nil) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:stationIdentifier];
annotationView.image = [UIImage bundleImageNamed:PIN_IMAGE];
annotationView.canShowCallout = YES;
UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
// N.B. In production code, you would need a more generic way to adjust
// height values instead of hard-coding values based on NSFoundationVersionNumber...
CGFloat height = (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) ? 55.f : 45.f;
detailButton.frame = CGRectMake(0.f, 0.f, 32.f, height);
annotationView.rightCalloutAccessoryView = detailButton;
}
return annotationView;
}此外,根据我到目前为止所看到的,如果同时指定左侧和右侧附件视图,则必须将这两个视图的高度设置为相同的值以获得正确的对齐方式。希望这个问题将在后续的iOS版本中得到解决,以避免编写此类代码……
发布于 2014-10-22 00:40:08
嗨,我遇到了完全相同的问题,这里是我为解决它所做的:
当MKAnnotation标题文本太长时,标注视图在显示文本时可能会出现问题。即使从你的屏幕截图中,你也可以看到只有当标题被截断并添加省略号时,问题才会发生。因此,标准MKAnnotation没有正确地布置视图,这是iOS8中的一个错误。
同时,您可以按照步骤here创建自己的自定义标注。
我认为这对于我所需要的工作来说太多了,所以我只是修剪了标题字符串,并添加了省略号以防止它试图自己做。(不是很理想,但这是一个快速的解决方案,文本无论如何都会被截断)
if (locTitle.length > 15)
{
locTitle = [NSString stringWithFormat:@"%@...", [locTitle substringToIndex:14]];
}https://stackoverflow.com/questions/25484608
复制相似问题