bye*_*ute 38 mapkit mkannotationview ios ios8
我仍然对iOS的东西很新,并且在测试我们的App for iOS 8兼容性时发现了一个问题.在iOS 7中一切正常,但在iOS 8上,rightCalloutAccessoryView在某些情况下未对齐.
第一个截图:正确对齐 
第二个屏幕截图:错误对齐 
如您所见,当InfoWindow具有较长的标题时会发生问题.但是在iOS 7上并非如此,我找不到任何提及这已经发生变化的事情?
我试图理解为什么并找到解决这个问题的方法,但还找不到任何东西.这是我们自己可以解决的还是我们必须为Apple提出问题?
任何帮助/想法都会受到高度赞赏,因为我对这个问题有点过分挑战.
添加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;
}
Run Code Online (Sandbox Code Playgroud)
您可能感兴趣,我(刚才)也将此问题添加到apple.developer.com上的iOS 8 Beta部分:https://devforums.apple.com/thread/242282 ? tstart = 0
如果我在这里或在apple.developer.com上得到答案,我会反映它,以便我们可以在两个网站上找到它
Mee*_*Bob 18
我通过设置autoresizingmask来修复垂直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];
Run Code Online (Sandbox Code Playgroud)
oct*_*cty 10
很难看,但我确实找到了解决这个问题的方法.
将附件视图高度设置为等于标注视图高度的值.我使用了硬编码值:
(您可能已经注意到默认注释标注视图的高度在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;
}
Run Code Online (Sandbox Code Playgroud)
另外,从我迄今所看到的,如果你同时指定左和右附件的意见,你就必须设置两个其高度为相同的值来获得正确对齐.希望这个问题将在后续的iOS版本中修复,以避免编写这种代码...
我注意到的一个好奇心是,我要显示的第一个标注将正确对齐附件视图,但后续选择不会。[view setNeedsLayout]我在返回出队的注释视图之前添加了一个调用,一切都开始再次正确对齐。
如果不花更多时间在这上面,我最好的猜测是,由于视图层次结构没有改变,因此已出列的视图不会触发重新布局。
不过,我强烈建议您针对此问题提交雷达。没有必要为这样的标准用例实施解决方法。
编辑:
虽然这对于许多情况来说似乎仍然更好,但我仍然遇到标题足够长而被截断的注释的问题。
| 归档时间: |
|
| 查看次数: |
9034 次 |
| 最近记录: |