3

マップがズームインおよびズームアウトしたときにMKAnnotationViewImageのサイズを変更しますか? この方法はiOS5では成功しますが、iOS6では失敗します。

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のサイズを変更できますか?誰か知ってる?

4

1 に答える 1

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;
于 2012-10-24T01:53:00.963 に答える