3

我正在尝试重新创建 UIViewAnimationTransitionFlipFromRight (和左)。我这样做的原因如下图所示,是在动画中间,当图层被遮挡时,对 AVCaptureVideoPreviewLayer 进行更改。UIViewAnimationTransitionFlipFromRight 不会让我中途停止动画,进行会话更改并继续,所以这是我最好的镜头。

虽然这可行,但它与 UIViewAnimationTransitionFlipFromRight 不同。图层开始旋转,但更多的是向后和对角滑动(很难描述),然后在动画的第二部分反转。我正在寻找图层的右侧翻转到后面,然后继续向左。相反,右侧从右侧开始,向后旋转,然后再次向右旋转。

我究竟做错了什么?

更新:它第一次正确旋转。之后,上面提到的问题仍然存在。与必须重置的 AVCaptureVideoPreviewLayer 有什么关系吗?不确定,只是猜测。

[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
                                                      }
                                      ];
                                 }
                             }
             ];
4

2 回答 2

1

您并没有说出“它与 UIViewAnimationTransitionFlipFromRight 不同”的意思。你看到透视了吗?我发现我需要在调用 CATransform3D 函数之前先指定 .m34 字段才能获得透视。在你声明你的转换之后和调用 CATransform3DMakeRotation 之前设置它。

于 2011-04-10T00:33:17.433 回答
0

我不完全确定,但也许你应该在完成动画时将 previewLayer.transform 重置为 CATransform3DIdentity?这可能就是您第二次运行它时看到奇怪的反向操作的原因。

于 2012-07-27T01:27:25.383 回答