我想将UIView添加到MKAnnotationView中作为图像。但是,首先,我想以UIView为单位旋转,然后在UIVIew中添加新的UIImage。你能帮帮我吗?我试过了,但UIView从不旋转。
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;
}发布于 2015-07-10 09:22:17
把这个去掉,
pinView.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(self.heading));加上这个,
pinImage.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(self.heading));在这之后,
UIImage *pinImage = [self imageFromUIView:pinView]; 所以最后的代码是,
UIView *pinView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 63, 63)];
pinView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"IconMapPin"]];
UIImage *pinImage = [self imageFromUIView:pinView];
pinImage.transform = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(self.heading));
annotationView.image = pinImage;https://stackoverflow.com/questions/31334328
复制相似问题