문제

내 앱에서 나는이 코드를 사용하여 마커가 배치되는지도를 확대합니다.

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {

    count++;

    if (count == arrayResults.count){

        MKMapRect zoomRect = MKMapRectNull;
        for (id <MKAnnotation> annotation in mapView.annotations)
        {
            MKMapPoint annotationP = MKMapPointForCoordinate(annotation.coordinate);
            MKMapRect pointRect = MKMapRectMake(annotationP.x, annotationP.y, 0.1, 0.1);
            if (MKMapRectIsNull(zoomRect)) {
                zoomRect = pointRect;
            } else {
                zoomRect = MKMapRectUnion(zoomRect, pointRect);
            }
        }
        [mapView setVisibleMapRect:zoomRect animated:YES];
    }

}

이것은 iOS 6에서는 잘 작동하지만 iOS 7에서는 그렇지 않습니다. 이유를 알고 있습니까? 감사해요

도움이 되었습니까?

해결책

이 코드는 매우 구체적인 대의원 호출 시퀀스에 의존합니다.

그만큼 count++ 그것을 가정합니다 didAddAnnotationViews 각 주석이 추가 된 후 대의원 방법은 즉시 및 별도로 호출됩니다.

이것은 iOS 버전에 관계없이 안전하지 않은 가정입니다.

이 축소 코드는 주석에 의존하지 않기 때문입니다 견해 Zooming을 수행하려면 (주석 만 있으면됩니다. 모델 -- 즉. 그만큼 id<MKAnnotation> 개체), 들어갈 필요가 없습니다 didAddAnnotationViews 처음에.

축소 코드를 넣습니다 (내부에 부품 if 블록), 주석을 추가하는 코드 바로 다음에 (아마도 for 통과하는 루프 arrayResults). 그것은 모든 iOS 버전에서 작동해야합니다.


또한 iOS 7에서는 새로운 것입니다 마시본화 : 애니메이션 : 방법은이 수동지도 직장 구조를 불필요하게 만듭니다. iOS 7에서는 다음과 같습니다.

[mapView showAnnotations:mapView.annotations animated:YES];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top