Angenommen, eine Kette von blockbasierten Animationen wie die folgende:
UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
//animation 1
[UIView animateWithDuration:2 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
view.frame = CGRectMake(0, 100, 200, 200);
} completion:^(BOOL finished){
//animation 2
[UIView animateWithDuration:2 delay:0 options: UIViewAnimationOptionRepeat |UIViewAnimationOptionAutoreverse animations:^{
[UIView setAnimationRepeatCount:1.5];
view.frame = CGRectMake(50, 100, 200, 200);
} completion:^(BOOL finished){
//animation 3
[UIView animateWithDuration:2 delay:0 options:0 animations:^{
view.frame = CGRectMake(50, 0, 200, 200);
} completion:nil];
}];
}];
Wie kann man diese Art von Animation am besten stoppen? Einfach aufrufen
[view.layer removeAllAnimations];
reicht nicht aus, denn dadurch wird nur der aktuell ausgeführte Animationsblock gestoppt und die übrigen werden nacheinander ausgeführt.