2011-04-09 53 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?這可能是您第二次運行它時看到奇怪的反向操作的原因。