自定义标注泡泡MKMapView
我想要做的是在MKMapView中创建一个自定义调出泡泡,就像http://blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/中所解释的那样,但似乎在那个很好的应用程序中有一些错误。 例如,当您将自定义标注气泡打开并滚动时,在某个点上,地图会滚动回打开的标注。 缩放有时也会触发此错误。 有没有人能够解决这些问题? 对不起创建一个新问题(因为有一对夫妇正在处理自定义标注泡泡),但我没有足够的代表点来回答评论。
对此的解决方法是在CalloutMapAnnotationView:didMoveToSuperview中,如果我们取消选择注释,则不要调用adjustMapRegionIfNeeded。
所以我修正它的方式是在我的mapViewController:didDeselectAnnotationView中,在我从mapView中删除Annotation之前,我将一个非零标记值赋给BasicMapAnnotationView。 我选择了159。
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view {
// distinguish between the map deselecting this and the user tapping on the callout.
// in the former case, we want to deselect as normal; latter case, show coupon detail.
if ( [view isKindOfClass:[BasicMapAnnotationView class]] ) {
if ( ((BasicMapAnnotationView *)view).calloutMapAnnotation ) {
if ( !((BasicMapAnnotationView *)view).preventSelectionChange) {
((BasicMapAnnotationView *)view).tag = 159; // prevent adjusting map - see CalloutMapAnnotationView
[mapView removeAnnotation: ((BasicMapAnnotationView *)view).calloutMapAnnotation];
// if we're deselecting the currently selected one, null out self.selectedAnnotationView
// Otherwise, the map view is deselecting this one in order to select another one
// and the timing is such that this nulling happens first, and the newly set AV would have no value for this.
if ( (BasicMapAnnotationView *)view == self.selectedAnnotationView ) {
self.selectedAnnotationView=nil;
}
((BasicMapAnnotationView *)view).calloutMapAnnotation = nil;
}
}
}
}
然后,在CalloutMapAnnotationView中,我检查这个值,如果找到了,我不会调整地图。
- (void)didMoveToSuperview {
if ( self.parentAnnotationView ) {
if ( self.parentAnnotationView.superview ) {
// null superview means it's been removed from map, and adjustMap gets wrong parentOrigin based on null superview,
// and recenters the map somewhere in Antarctica. The Ross Ice Shelf has no coupons except for frozen penguin eggs.
if ( self.parentAnnotationView.tag != 159 ) {// Don't adjust map region on deselect.
//159 hardcoded in MapViewController:didDeselectAnnotationView
[self adjustMapRegionIfNeeded];
}
[self animateIn];
}
}
}
链接地址: http://www.djcxy.com/p/67275.html