我想在系列中創建一組動畫。 例如iOS系列動畫系列
淡入2秒
旋轉2秒
淡出2秒
什麼是實現這一目標的最佳途徑?我試圖使用CAAnimation小組,但似乎並行地爲其動畫數組製作動畫。我想做一個動畫1,然後做動畫2,然後做動畫3(系列)
我想在系列中創建一組動畫。 例如iOS系列動畫系列
淡入2秒
旋轉2秒
淡出2秒
什麼是實現這一目標的最佳途徑?我試圖使用CAAnimation小組,但似乎並行地爲其動畫數組製作動畫。我想做一個動畫1,然後做動畫2,然後做動畫3(系列)
您應該對所有這些動畫使用基於塊的動畫。
對於這樣一個動畫的animateKeyFrames
塊將是完美的......
// set duration for the entire sequence of animations
[UIView animateKeyFramesWithDuration:6
delay:0
options:0
animations:^{
// add fade in keyframe
// starts at 0% lasts for 33% of animation
[UIView addKeyFrameWithRelativeStartTime:0
relativeDuration:0.333
animations:^{
view.alpha = 1.0;
}];
// add rotation key frame
// starts at 33% lasts for 33% of animation
[UIView addKeyFrameWithRelativeStartTime:0.333
relativeDuration:0.333
animations:^{
view.transform = CGAffineTransformMakeRotation(rotationAngle);
}];
// add fade out key frame
// starts at 66% lasts for 33% of animation
[UIView addKeyFrameWithRelativeStartTime:0.666
relativeDuration:0.333
animations:^{
view.alpha = 0.0;
}];
}
completion:nil];
@Rob哎呀!完成了,謝謝。 – Fogmeister
淡入和淡出工作正常 - 旋轉不會發生。我在Radians 6.28中指定了360度的旋轉角度 - 任何建議。? – OneGuyInDc
啊,首先你應該用'M_PI'來代替pi,然後再乘以2.不是6.28。其次,因爲2π弧度與0相同,它不會旋轉。將旋轉分爲兩部分。一輪旋轉到M_PI,另一輪旋轉到2 * M_PI,您將不得不更新時間。 – Fogmeister
現在,你通常會通過animateKeyframesWithDuration
使用UIView
塊動畫。指定6秒的動畫持續時間,然後將三個調用分別添加到addKeyframeWithRelativeStartTime
,分別從相對起始時間0,0.333和0.666開始,每個持續時間爲0.333,並在這三個動畫塊中執行適當的動畫。
使用動畫組,但致命的每個動畫,直到前應該已經結束。 – rckoenes