2012-08-27 61 views
0

我試圖實現以下的動畫:的UIView組動畫

yourSubView.transform = CGAffineTransformMakeScale(0.01, 0.01); 
[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
//change time duration according to requirement 
// animate it to the identity transform (100% scale) 
yourSubView.transform = CGAffineTransformIdentity; 
} completion:^(BOOL finished){ 
// if you want to do something once the animation finishes, put it here 
}]; 

與子視圖的一些運動相結合。我知道核心動畫你可以結合動畫,但你怎麼能在UIView動畫中做到這一點?

我可以將此代碼從UIView動畫轉換爲Core動畫嗎?

yourSubView.transform = CGAffineTransformMakeScale(0.01, 0.01); 
[UIView animateWithDuration:0.4 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
//change time duration according to requirement 
// animate it to the identity transform (100% scale) 
yourSubView.transform = CGAffineTransformIdentity; 
} completion:^(BOOL finished){ 
// if you want to do something once the animation finishes, put it here 
}]; 

回答

2

您可以通過更改多個動畫屬性來合併動畫。例如,您也可以設置您的SubView.alpha,然後更改動畫塊中的Alpha。它將規模和阿爾法變化結合在一起。

做一個簡單的翻譯,試試這個在你的動畫塊:

yourSubView.transform = CGAffineTransformTranslate(CGAffineTransformIdentity, 100.0, 100.0); 

這應該與移動在X和Y方向100像素沿着設定比例回身份。

對於核心動畫,這個Grouping two Core Animations with CAAnimationGroup causes one CABasicAnimation to not run應該讓你開始。您將使用CAAnimationGroup合併多個動畫,並且可以執行包括3D旋轉在內的漂亮功能。

規範化:

CAKeyframeAnimation *scale = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale"]; 
[scale setValues:[NSArray arrayWithObjects:[NSNumber numberWithFloat:0.01f],[NSNumber numberWithFloat:1.0f],nil]]; 
[scale setKeyTimes:[NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],[NSNumber numberWithFloat:0.4f],nil]]; 

[mySubview.layer addAnimation:scale forKey:@"myScale"]; 
+0

代碼如何可以轉換到核心動畫:yourSubView.transform = CGAffineTransformMakeScale(0.01,0.01); [UIView的animateWithDuration:0.4延遲:0選項:UIViewAnimationOptionCurveEaseOut動畫:^ {根據需要 //變化持續時間 //它動畫的恆等變換(100%比例) yourSubView.transform = CGAffineTransformIdentity; }完成:^(BOOL完成){ //如果您想在動畫完成後執行某些操作,請將其放在這裏 }]; – Juan

+0

編輯答案顯示縮放的例子 – CSmith