我在自定義UIView,anim1和anim2中有兩個動畫。 Anim1將它的委託設置爲self,並且在我的類中有一個animationDidStop方法觸發Anim2。如果我想在Anim2完成時發生其他事情,我該怎麼做?我可以使用不同的名稱指定委託方法嗎?核心動畫animationDidStop與鏈接動畫
UPDATE
我聲明兩個動畫作爲IVARS:
CABasicAnimation *topFlip;
CABasicAnimation *bottomFlip;
我建立每個動畫並設置delgate自例如
- (CABasicAnimation *)bottomCharFlap: (CALayer *)charLayer
{
bottomFlip = [CABasicAnimation animationWithKeyPath:@"transform"];
charLayer.transform = CATransform3DMakeRotation(DegreesToRadians(0), 1, 0, 0); //set to end pos before animation
bottomFlip.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(DegreesToRadians(-360), 1, 0, 0)];
bottomFlip.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeRotation(DegreesToRadians(-270), 1, 0, 0)];
bottomFlip.autoreverses = NO;
bottomFlip.duration = 0.5f;
bottomFlip.repeatCount = 1;
bottomFlip.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseOut];
bottomFlip.delegate = self;
bottomFlip.removedOnCompletion = FALSE;
return bottomFlip;
}
然後我試圖找到bottomFlip在animationdidStop:
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
if (theAnimation == bottomFlip) {
NSLog(@"Bottom Animation is: %@", bottomFlip);
}
NSLog(@"Animation %@ stopped",theAnimation);
[bottomHalfCharLayerFront addAnimation:[self bottomCharFlap:bottomHalfCharLayerFront] forKey:@"bottomCharAnim"];
bottomHalfCharLayerFront.hidden = NO;
topHalfCharLayerFront.hidden = YES;
//insert the next one???
}
「動畫停止」記錄,但沒有別的也就是說,它似乎並沒有認識到bottomFlip伊娃
謝謝!這可以通過addAnimation forKey的'forKey'來完成嗎?或者,這隻適用於刪除動畫? – codecowboy 2010-08-31 03:23:37
我已經在上面添加了一些代碼。如果我在添加動畫後記錄動畫的內存地址,然後將其記錄在animationDidStop中,則內存地址不匹配。我認爲這就是爲什麼你的建議沒有奏效。如果(theAnimation == anim1)從未成功。 – codecowboy 2010-08-31 06:04:54