2011-04-09 73 views
3

我试图重新创建UIViewAnimationTransitionFlipFromRight(和左)。如下所示,我的理由是在动画中间改变AVCaptureVideoPreviewLayer,当图层被遮挡时。 UIViewAnimationTransitionFlipFromRight不会让我停止一半动画,改变会话并继续,所以这里是我最好的选择。使用CATransform3D创建翻转动画

虽然这工作,它只是不同于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 
                 } 
             ]; 
           } 
          } 
      ]; 

回答

1

你不说你的意思是“这只是不一样UIViewAnimationTransitionFlipFromRight”。你看到了透视吗?我发现我需要在调用CATransform3D函数之前先指定.m34字段,以获得透视。在声明变换之后并在调用CATransform3DMakeRotation之前设置该值。

+0

我肯定会尝试。在我的监督下,我会更新OP。 – 2011-04-10 02:41:31

+0

我还发现,它似乎在我第一次调用它时会执行正确的动画,但是每隔一段时间,它都会将动画做一半并自行反转。 – 2011-04-11 02:40:38

0

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