Wie Sie angeben, Selektor, wenn CAKeyframeAnimation fertig ist?

Ich bin mit einem CAKeyframeAnimation zu animieren, eine Ansicht entlang einer CGPath. Wenn die animation fertig ist, möchte ich in der Lage sein, um eine andere Methode zum ausführen einer anderen Aktion. Ist es ein guter Weg, dies zu tun?

Habe ich mir angeschaut mit UIView ' s setAnimationDidStopSelector:, aber von den docs-das sieht aus wie es nur gilt, wenn Sie innerhalb einer UIView animation-block (beginAnimations und commitAnimations). Ich auch gab, es zu versuchen, nur für den Fall, aber es scheint nicht zu funktionieren.

Hier einige Beispiel-code (dieser ist in einer benutzerdefinierten UIView-Unterklasse-Methode):

//These have no effect since they're not in a UIView Animation Block
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];    

//Set up path movement
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"path"];
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
pathAnimation.duration = 1.0f;

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, self.center.x, self.center.y);

//add all points to the path
for (NSValue* value in myPoints) {
    CGPoint nextPoint = [value CGPointValue];
    CGPathAddLineToPoint(path, NULL, nextPoint.x, nextPoint.y);
}

pathAnimation.path = path;
CGPathRelease(path);

[self.layer addAnimation:pathAnimation forKey:@"pathAnimation"];

Einen workaround, die ich war, wenn man bedenkt, dass sollte funktionieren, aber scheint nicht der beste Weg, ist die Verwendung von NSObject ist performSelector:withObject:afterDelay:. So lange, wie ich die Verzögerung gleich der Dauer der animation, dann sollte es in Ordnung sein.

Gibt es eine bessere Möglichkeit? Danke!

InformationsquelleAutor Daren | 2010-03-18
Schreibe einen Kommentar