在iPhone上旋转图像的最快方法

时间:2009-06-22 09:23:41

标签: iphone graphics uiimage

我需要根据用户输入旋转UIImage。我希望它尽可能光滑,因此想知道哪种是执行转换和渲染的最快方法。理想情况下,我想留在UIKit或Quartz框架内。图像的属性如下:

  • 尺寸约为250x300像素
  • 不透明 - 需要使用Alpha通道进行渲染

实现此功能的最佳方法和实践是什么?

注意:stackoverflow answer中描述了一种方法,但我不确定这是否是最佳的。我当然会试一试,但我很想知道这是否被认为是“最佳实践”。

2 个答案:

答案 0 :(得分:6)

将核心动画层应用于UIImage的示例可能会提供一些灵感:

UIImage* rotatingImage = [UIImage imageNamed:@"someImage.png"];

CATransform3D rotationTransform = CATransform3DMakeRotation(1.0f * M_PI, 0, 0, 1.0);
CABasicAnimation* rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];

rotationAnimation.toValue = [NSValue valueWithCATransform3D:rotationTransform];
rotationAnimation.duration = 0.25f;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 10;

[rotatingImage.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];

答案 1 :(得分:1)

如果您在UIImageView中显示UIImage,为什么不在视图上设置transform属性?

myimageView.transform = CGAffineTransformMakeRotation(<angle in radians>);

就像那样简单,对于像你这样谈论的小图像来说,这是非常高效的 - 所有UIKit视图都是图层支持的,所以它的硬件加速了。此属性也是可动画的。

相关问题