2012-09-28 2 views
3

Resize MKAnnotationView Image When map zooms in and out?이 메도는 iOS5에서는 성공했지만 iOS6에서는 실패했습니다.iOS6에서 MKAnnotationView의 크기를 조정하는 방법은 무엇입니까?

MKAnnotationView의 변환이 직접 변경되어 행운이 없습니다. MKAnnotationView는 플래시로만 크기가 조정됩니다 (MKMapView 내부를 터치 업하면 터치 업 완료 후 MKAnnotationView가 원래 크기로 복원됩니다).

내 코드는 다음과 같습니다 :

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { 
for (id <MKAnnotation>annotation in _mapView.annotations) { 
    // if it's the user location, just return nil. 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
     continue; 

    // handle our custom annotations 
    // 
    if ([annotation isKindOfClass:[XPMKAnnotation class]]) 
    { 
     // try to retrieve an existing pin view first 
     MKAnnotationView *pinView = [_mapView viewForAnnotation:annotation]; 
     //resize the pin view 
     double zoomLevel = [_mapView getZoomLevel]; 
     double scale = (1.0 * zoomLevel/16) + 0.5; 
     pinView.transform = CGAffineTransformMakeScale(scale, scale); 
    } 
    } 
} 

우리가 iOS6의에 MKAnnotationView의 크기를 조정할 수 있습니까? 아무도 몰라요?

+0

에서 줌 레벨로 다시 조정. 마치 Transform이 AnnotationView에 대해 재설정 된 것처럼 계속 깜박입니다. 솔루션을 찾으면 여기에 게시됩니다. – Bach

답변

3

Apple은 주석보기의 .image 속성 크기를 조정할 것을 제안합니다. 아래 내 경우, 나는 viewforAnnotation에 설정 한있는 UIImage에서보고 여기에 같은 문제를 가진 UIPinchGestureRecognizer

UIImage *orangeImage = [UIImage imageNamed:@"Orange210.PNG"]; 
    CGRect resizeRect; 
    //rescale image based on zoom level 
    resizeRect.size.height = orangeImage.size.height * scale; 
    resizeRect.size.width = orangeImage.size.width * scale ; 
    NSLog(@"height = %f, width = %f, zoomLevel = %f", resizeRect.size.height, resizeRect.size.width,zoomLevel); 
    resizeRect.origin = (CGPoint){0,0}; 
    UIGraphicsBeginImageContext(resizeRect.size); 
    [orangeImage drawInRect:resizeRect]; 
    UIImage *resizedImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    pinView.image = resizedImage; 
+0

Erik Gross, 저에게 큰 도움을 주셔서 감사합니다. – user501836

+0

FYI,'getZoom'은 여기에서 논의되는 카테고리에서 온 것입니다 : http://stackoverflow.com/questions/7657207/how-to-detect-that-mkmapview-is-zoomed-out-in – eulr

+0

여기 계량은 무엇입니까 – Vishnu

관련 문제