如何在iOS6上调整MKAnnotationView的大小? [英] How to resize MKAnnotationView on iOS6?
问题描述
调整MKAnnotationView Image的大小当地图放大和缩小时?该方法在iOS5上成功,但在iOS6上失败.
Resize MKAnnotationView Image When map zooms in and out? This methord are successful on iOS5, but failed on iOS6.
我直接更改了MKAnnotationView的转换,没有任何运气. MKAnnotationView只能在瞬间调整大小(在MKMapView中进行修饰时,修饰完成后,MKAnnotationView将恢复原始大小).
I change the MKAnnotationView's transform directly, and no luck. The MKAnnotationView only resize in a flash(When touch up inside the MKMapView, after the touch up finish, the MKAnnotationView will restore the original size).
我的代码如下:
- (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的大小吗?有人知道吗?
Can we resize the MKAnnotationView on iOS6? Anybody know any way?
推荐答案
Apple建议调整注释视图的.image属性的大小.在下面的示例中,我查看了在viewforAnnotation中设置的UIImage,并将其重新缩放到UIPinchGestureRecognizer
Apple suggests resizing the .image property of an annotation view. In my case shown below, I looked at the UIImage that was set in the viewforAnnotation and re-scaled it to the zoom level in a 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;
这篇关于如何在iOS6上调整MKAnnotationView的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!