iOS开发 想旋转UIImage90度 但是毫无效果

用这个方法[UIImage imageWithCGImage:img.CGImage scale:2.0 orientation:UIImageOrientationRight]
想旋转UIImage90度 但是毫无效果

阅读 5.7k
2 个回答

你那个原图片 img 的 orientation 是什么?我猜可能本来就是 right,所以重新建一个 orientation 是 right 的 UIImage 是没有任何变化的。

你需要先修正一下原图片的方向:https://gist.github.com/alex-cellcity/1531596

clipboard.png
下面的代码可以正确旋转图片。

UIImage *img = [UIImage imageNamed:@"i"];
UIImageOrientation a0 = img.imageOrientation;
UIImage *image = [UIImage imageWithCGImage:img.CGImage scale:2.0 orientation:UIImageOrientationRight];
UIImageOrientation a2 = image.imageOrientation;

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
[imageView sizeToFit];
[self.view addSubview:imageView];
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题