Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c MKAnnotationView带旋转的图像_Objective C_Uiview_Rotation_Uiimage_Mkannotationview - Fatal编程技术网

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;