Iphone 自定义详图索引编号MKMapView

Iphone 自定义详图索引编号MKMapView,iphone,mkmapview,Iphone,Mkmapview,我想做的是在MKMapView中创建一个自定义标注气泡,正如中所解释的,但是在这个做得很好的应用程序中似乎存在一些bug。例如,当您将自定义详图索引编号保持打开状态并向外滚动时,地图会在某个点上滚动回打开的详图索引。缩放有时也会触发此错误。有人能解决这些问题吗?很抱歉创建了一个新问题,因为有两个自定义调用气泡,但我没有足够的代表点来评论答案。此问题的解决方法在callout MapAnnotationView:didMoveToSuperview中, 如果要取消选择注释,则不要调用AdjustM

我想做的是在MKMapView中创建一个自定义标注气泡,正如中所解释的,但是在这个做得很好的应用程序中似乎存在一些bug。例如,当您将自定义详图索引编号保持打开状态并向外滚动时,地图会在某个点上滚动回打开的详图索引。缩放有时也会触发此错误。有人能解决这些问题吗?很抱歉创建了一个新问题,因为有两个自定义调用气泡,但我没有足够的代表点来评论答案。

此问题的解决方法在callout MapAnnotationView:didMoveToSuperview中, 如果要取消选择注释,则不要调用AdjustMapRegionIfNeed

因此,我在mapViewController中修复它的方法是:取消AnnotationView,在从mapView中删除注释之前,我将非零标记值指定给BasicMapNotationView。我选择了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];
    } 
}
}

该示例中是否有应关闭详图索引但不关闭的代码?也许你可以在这里提供一个相关的摘录,我们可以试着看看为什么它不起作用。我认为在模仿苹果的行为时,任何代码都不应该关闭它,除非他们在它变得可见时再次打开它,也许你的意思是?这肯定是一个bug。我已经使用此代码一段时间了,但从未遇到过此案例。基本上,如果您将标注气泡从视图中滚动出来,然后点击地图,它会认为您正在点击标注,并且标注不会显示,因此它会重新调整屏幕,以便显示标注。这件事得做一段时间。感谢您找到bug.BasicMapNotationView没有属性calloutMapAnnotation,添加它也没有多大好处,因为除了nil之外,没有任何值被分配给它,尽管目前无法达到该值。也许我遗漏了什么?你能提供完整的代码吗?除非我完全遗漏了什么,否则在第1部分和第2部分中都没有给出任何合理的值。我尝试了您提供的添加内容,但它们不起作用,我想应该归咎于Callout MapAnnotation属性。