2013-06-04 30 views
1

編輯與正確的觀察。CATransform3應用錨點後效果消失

我用以下兩個片段來旋轉UIImageView。 stage1後,我得到了所需的3D效果:視圖旋轉(3D效果)和拉伸(更大的尺寸)。在舞臺2上,我試圖用右側的鉸鏈擺動右側的視圖。

如果我應用了更改定位點的線,視圖會正確擺動(右轉),但存在一個主要問題:視圖的大小恢復爲原始大小(較小),而(旋轉)3D效果仍然完好無損,然後發生擺動。

有什麼建議嗎?

rightView.layer.anchorPoint = CGPointMake(1.0, 0.5); 


-(void)stage1 
{ 
    [UIView animateWithDuration:1.5 animations:^{ 
     rightView.transform = CGAffineTransformMakeTranslation(0,0); //rightView i UIImageView 
     CATransform3D _3Dt = CATransform3DIdentity; 
     _3Dt =CATransform3DMakeRotation(3.141f/42.0f,0.0f,-1.0f,0.0f); 
     _3Dt.m34 = -0.001f; 
     _3Dt.m14 = -0.0015f; 
     rightView.layer.transform = _3Dt; 
    } completion:^(BOOL finished){ 
     if (finished) { 
      NSLog(@"finished.."); 
     } 
    }]; 
} 

-(void)Stage2 
{ 
    rightView.layer.anchorPoint = CGPointMake(1.0, 0.5); //issue? 
    rightView.center = CGPointMake(1012, 384); 
    [UIView animateWithDuration:1.75 animations:^{ 
     CATransform3D rightTransform = rightView.layer.transform; 
     rightTransform.m34 = 1.0f/500; 
     rightTransform = CATransform3DRotate(rightTransform, M_PI_2, 0, 1, 0); 
     rightView.layer.transform = rightTransform; 
    } completion:^(BOOL finished) { 
    }]; 
} 
+0

更改anchorpoint也改變被應用的變換方式。您能否在例如生成想要的結果的圖像? Photoshop的?初始狀態,stage1動畫完成時的狀態,stage2動畫完成時的狀態? – hfossli

+0

@hfossli,添加圖片。我還在stage2動畫發生之前添加了一張圖片。請注意,我可以在stage2動畫之前使用setFrame改變rightView的框架,但我無法在stage1動畫之後使其與原始3D效果(角度等)相匹配。 – user523234

+0

您上傳了所需圖像或「錯誤」輸出的圖像? – hfossli

回答

1

您需要在「選項」與時間添加到您的動畫,並添加options:UIViewAnimationOptionBeginFromCurrentState

否則它再次開始啓動。

所以,你的第2階段是這樣的:

-(void)Stage2 
{ 
    rightView.layer.anchorPoint = CGPointMake(1.0, 0.5); //issue? 
    rightView.center = CGPointMake(1012, 384); 
    [UIView animateWithDuration:1.75 
          delay:0.00 
         options:UIViewAnimationOptionBeginFromCurrentState 
        animations:^{ 
     CATransform3D rightTransform = rightView.layer.transform; 
     rightTransform.m34 = 1.0f/500; 
     rightTransform = CATransform3DRotate(rightTransform, M_PI_2, 0, 1, 0); 
     rightView.layer.transform = rightTransform; 
    } completion:^(BOOL finished) { 
    }]; 
} 
+0

我試過了,但它產生了相同的結果。就像我的原始片段一樣,如果我沒有設置anchorPoint,那麼原始的轉換效果是完整的。 anchorPoint似乎是罪魁禍首。還有其他建議嗎? – user523234

+0

我原來的觀察錯了。如果你仍然感興趣,請查看更新。謝謝。 – user523234

+0

在我的情況下,它的一層。任何屬性設置CABasicAnimation從圖層的當前狀態開始? – Nil