Objective c MKAnnotationView带旋转的图像
我想将Objective c MKAnnotationView带旋转的图像,objective-c,uiview,rotation,uiimage,mkannotationview,Objective C,Uiview,Rotation,Uiimage,Mkannotationview,我想将UIView添加到MKAnnotationView作为图像。但首先我想按度数旋转UIView,然后将新的UIImage添加到UIView。你能帮助我吗?我试过了,但视图从未旋转过 UIView *pinView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 63, 63)]; pinView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:
UIView
添加到MKAnnotationView
作为图像。但首先我想按度数旋转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;
}
去掉这个,
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;