我想在自定义程度上旋转UIImage(而不是UIImageView)我跟着这篇文章,但它对我不起作用.
有人可以帮忙吗?谢谢.
更新:下面的代码执行了一些工作,但是在旋转之后我丢失了一些图像:

为了做到这一点,我应该改变什么?(顺便说一下截图中的黄色是我的UIImageView bg)
- (UIImage *) rotate: (UIImage *) image
{
double angle = 20;
CGSize s = {image.size.width, image.size.height};
UIGraphicsBeginImageContext(s);
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextTranslateCTM(ctx, 0,image.size.height);
CGContextScaleCTM(ctx, 1.0, -1.0);
CGContextRotateCTM(ctx, 2*M_PI*angle/360);
CGContextDrawImage(ctx,CGRectMake(0,0,image.size.width, image.size.height),image.CGImage);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
Run Code Online (Sandbox Code Playgroud)