如何同时使图像旋转和3D变换? [英] How to make image rotation and 3D transform simultaneously?

查看:42
本文介绍了如何同时使图像旋转和3D变换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究图像编辑应用程序(调整大小,旋转,3d变换).如果我旋转图像,然后进行3D变换.它会变成初始图像.否则我将更改3D变换然后进行旋转,它也会进入初始状态.

I am working on image editing application(resize, rotation, 3d transform). If I am rotate the image and then make 3D transform. Its going to initial image. Otherwise I am change the 3D transform then make rotation, Its also goes to the initial state.

对于图像3D转换,我正在使用以下代码:

For image 3D Transform I am using below code :

- (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;
        }
 }

对于图像旋转,我使用以下代码:

For image Rotation I am using below code :

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

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

How to I fix this issue. Always welcome your suggestions, sample code, Sample project, any App store applications. Thanks in advance. Any one help me.

推荐答案

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

Use CAAnimationGroup to combine multiple animation into one

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"];

这篇关于如何同时使图像旋转和3D变换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆