如何同时进行图像旋转和3D变换?

时间:2012-09-21 06:38:43

标签: iphone

我正在处理图像编辑应用程序(调整大小,旋转,三维变换)。如果我旋转图像然后进行3D变换。它将进入初始形象。否则我改变3D变换然后进行旋转,它也进入初始状态。

对于图像3D变换我使用下面的代码:

- (void)moveImage:(UIPanGestureRecognizer *)recognizer
{
        if ([recognizer respondsToSelector:@selector(translationInView:)]) {
            CGPoint translation = [(UIPanGestureRecognizer *)recognizer translationInView:recognizer.view.superview];

            CALayer *layer = self.layer;
            CATransform3D rotationAndPerspectiveTransform = CATransform3DIdentity;
            rotationAndPerspectiveTransform.m34 = 1.0 / 500.0;
            rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, - self.xTranslation / 50.0 * M_PI / 180.0f, 0.0f, 1.0f, 0.0f);
            layer.transform = rotationAndPerspectiveTransform;
            rotationAndPerspectiveTransform.m34 = - 1.0 / 500.0;
            rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, - self.yTranslation / 50.0 * M_PI / 180.0f, 1.0f, 0.0f, 0.0f);
            layer.transform = rotationAndPerspectiveTransform;
        }
 }

对于图像旋转我使用下面的代码:

- (void)rotateImage:(UIRotationGestureRecognizer *)recognizer
{
    if (state == RSImageViewStateResizing) {
        recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation);
        recognizer.rotation = 0;
    }
}

如何解决此问题。随时欢迎您的建议,示例代码,示例项目,任何App Store应用程序。提前致谢。任何人都帮助我。

1 个答案:

答案 0 :(得分:0)

使用CAAnimationGroup将多个动画合并为一个

CAAnimationGroup *theGroup = [CAAnimationGroup animation];
theGroup.animations=[NSArray arrayWithObject:resizeAnimation, rotationAnimation, 3d transformAnimation];// add here your CAAnimation reference and CATransform3D reference
[layer addAnimation:theGroup forKey:@"animatePosition"];