0
我想實現一個嵌套的動畫塊。我面臨的問題是隻有我的完成塊代碼被調用。當我發表評論時,最初的部分被調用。如何讓動畫完成第一個動畫,然後再調用第二個動畫?UIView動畫塊問題
- (void)viewDidAppear:(BOOL)animated
{
_finalLogoCenter = self.logoImage.center;
// Logo Animation
[self logoAnimation];
}
- (void) logoAnimation
{
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionTransitionNone
animations:^ {
// Move Up
[self moveLogoUpFirst];
}completion:^(BOOL finished)
{
// Move below final point
[self moveLogoDownBeyondFinalPoint];
}];
}
- (void) moveLogoUpFirst
{
__block CGPoint logoCenter = self.logoImage.center;
logoCenter.y = 290.0f;
self.logoImage.center = logoCenter;
[self.logoImage setAlpha:0.0f];
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionTransitionNone
animations:^ {
logoCenter.y = _finalLogoCenter.y - 20;
self.logoImage.center = logoCenter;
[self.logoImage setAlpha:1.0f];
}completion:nil];
}
- (void) moveLogoDownBeyondFinalPoint
{
__block CGPoint logoCenter = self.logoImage.center;
self.logoImage.center = logoCenter;
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionTransitionNone
animations:^ {
logoCenter.y = _finalLogoCenter.y + 5;
self.logoImage.center = logoCenter;
}completion:nil];
}
嘗試用performSelector waitUntilDone – Jasper
@JasperPol謝謝。這確實有效。但我需要計算以前的動畫的時間,並在afterDelay中設置它。完成塊不會處理這個問題嗎? – Anil
好吧,你知道動畫需要1秒,所以完成塊在1秒後被觸發。檢查這個答案,它可能是一個更好的方式來動畫你想要做的事情:http://stackoverflow.com/questions/1632364/shake-visual-effect-on-iphone-not-shaking-the-device/10007898# 10007898 – Jasper