使用CATransform3D创建翻转动画 [英] Using CATransform3D to create flip animation

查看:146
本文介绍了使用CATransform3D创建翻转动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新创建UIViewAnimationTransitionFlipFromRight(和左)。我这样做的原因,如下所示,是在图层被阻挡时,在动画中间对AVCaptureVideoPreviewLayer进行更改。 UIViewAnimationTransitionFlipFromRight不会让我停止动画半路上,使会议的改变,并继续执行,所以这里是我在它最好的拍摄。

I'm trying to recreate UIViewAnimationTransitionFlipFromRight (and left). My reason for doing so, as shown below, is to make changes to AVCaptureVideoPreviewLayer in the middle of the animation, when the layer is obstructed. UIViewAnimationTransitionFlipFromRight won't let me stop the animation half way, make session changes, and continue, so here is my best shot at it.

虽然这个工作,它只是不与UIViewAnimationTransitionFlipFromRight相同。图层开始旋转,但更多的是幻灯片,向后和对角线(非常难以描述),然后在动画的第二部分进行反转。我正在寻找图层的右侧翻转到后面,然后继续向左。相反,右侧从右侧开始,向后旋转,然后再次向右旋转。

While this works, it's just not the same as UIViewAnimationTransitionFlipFromRight. The layer starts to rotate, but more of a slide, backwards and diagonally (very hard to describe), and then reverses for the second part of the animation. I'm looking for the right side of the layer to flip to the back, and then continue to the left. Instead, the right side starts on the right, rotates to the back, and then rotates to the right again.

我做错了什么?

更新:
第一次正确旋转。之后,上述问题仍然存在。是否与AVCaptureVideoPreviewLayer有关,必须重置? 。不肯定,只是猜测

UPDATE: It rotates properly the first time. After that, the problem mentioned above persists. Is there something to do with the AVCaptureVideoPreviewLayer that has to be reset? Not sure, just a guess.

[UIView animateWithDuration:1.5 delay:0.0 
                                options:UIViewAnimationCurveEaseIn 
                             animations:^{
                                 CATransform3D frontTransform = CATransform3DIdentity;
                                 frontTransform.m34 = 1.0 / -850.0;
                                     frontTransform = CATransform3DMakeRotation(M_PI_2,0.0,1.0,0.0); //flip halfway
                                     frontTransform = CATransform3DScale(frontTransform, 0.835, 0.835, 0.835);
                                 previewLayer.transform = frontTransform;

                             }
                             completion:^(BOOL finished){
                                 if (finished) {

                                     [previewLayer setAutomaticallyAdjustsMirroring:NO];
                                     [previewLayer setMirrored:NO];

                                     [session beginConfiguration];
                                     [[self captureManager] setMirroringMode:AVCamMirroringOff];
                                     [session commitConfiguration];

                                     [UIView animateWithDuration:1.5
                                                           delay:0.0 
                                                         options:UIViewAnimationCurveEaseOut 
                                                      animations:^{
                                                          CATransform3D backTransform = CATransform3DIdentity;
                                                          backTransform.m34 = 0.0f;
                                                              backTransform = CATransform3DMakeRotation(M_PI,0.0,1.0,0.0); //finish the flip
                                                              backTransform = CATransform3DScale(backTransform, 1.0, 1.0, 1.0);
                                                          previewLayer.transform = backTransform;
                                                      }
                                                      completion:^(BOOL finished){
                                                              //nothing upon completion
                                                      }
                                      ];
                                 }
                             }
             ];


推荐答案

你没有说你是什么意思与UIViewAnimationTransitionFlipFromRight不一样。你看到了视角吗?我发现在调用CATransform3D函数之前我需要先指定.m34字段才能获得透视图。在声明转换之后和调用CATransform3DMakeRotation之前立即设置。

You don't say what you mean by "it's just not the same as UIViewAnimationTransitionFlipFromRight". Are you seeing perspective? I've found that I need to specify the .m34 field first prior to calling the CATransform3D functions in order to get perspective. Set that right after you declare your transform and before your call to CATransform3DMakeRotation.

这篇关于使用CATransform3D创建翻转动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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