3
我想添加UIView
到MKAnnotationView
作爲圖像。但首先我要旋轉UIView
,然後添加新的UIImage
到UIVIew
。你可以幫我嗎?我試過但UIView從不旋轉。MKAnnotationView旋轉的圖像
UIView *pinView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 63, 63)];
pinView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"IconMapPin"]];
pinView.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(self.heading));
UIImage *pinImage = [self imageFromUIView:pinView];
annotationView.image = pinImage;
方法轉換的UIView到的UIImage
- (UIImage *) imageFromUIView:(UIView*)view
{
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}