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

tea*_*bot 0 iphone graphics uiimage

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

  • 大小约为250x300像素
  • 不透明 - 需要使用alpha通道进行渲染

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

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

Nat*_*ies 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"];
Run Code Online (Sandbox Code Playgroud)