Как сделать паузу и возобновить анимацию UIView:
Это расскажет, как это сделать без блочной анимации. (Люди все еще хотят поддерживать 3.0 и выше).
Это позволяет делать паузу только после того, как анимация достигла заданного местоположения. Для того, чтобы приостановить анимацию в середине анимации, я предлагаю использовать CALayers как:
CALayer* myLayer = [self.myUIView.layer presentationLayer];
CGRect frameStop = myLayer.frame;
double pausedX = frameStop.origin.x;
double pausedY = frameStop.origin.y;
Теперь о том, как:
startAnimation = [UIButton buttonWithType:UIButtonTypeRoundedRect];
startAnimation.titleLabel.font = [UIFont systemFontOfSize:22];
startAnimation.titleLabel.lineBreakMode = UILineBreakModeHeadTruncation;
[startAnimation setTitle:(@"pause") forState:UIControlStateNormal];
[startAnimation addTarget:self action:@selector(doAnimation) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:startAnimation];
-(void)doAnimation{
if (bicyclePad.animationPause == false){
[restartAnimation setTitle:(@"Resume") forState:UIControlStateNormal];
[bicyclePad pauseAnimation];
} else {
[restartAnimation setTitle:(@"Pause") forState:UIControlStateNormal];
[bicyclePad resumeAnimation];
}
}
-(void)resumeAnimation{
bicyclePad.animationPause = false;
[restartAnimation setTitle:(@"Resume") forState:UIControlStateNormal];
objectMotion = [[yourUIView alloc]initWithFrame:CGRectMake((*yourPathPoints)[0].x, (*yourPathPoints)[0].y, 8, 8)];
[self.view addSubview:objectMotion];
[self animateBike:nil finished:YES context:nil];
}
-(void)pauseAnimation{
bicyclePad.animationPause = true;
[restartAnimation setTitle:(@"Pause") forState:UIControlStateNormal];
[bicyclePad doAnimation];
}
-(void)animateObject:(NSString*)animationID finished:(BOOL)finished context:(void*)context {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
//below suggesting your animation loops
if (animationPause == true)
[UIView setAnimationDidStopSelector:@selector(animateStop:finished:context:)];
else
[UIView setAnimationDidStopSelector:@selector(animateObject:finished:context:)];
[UIView setAnimationDelegate:self];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
[UIView setAnimationDuration:yourDelay];
[UIView commitAnimations];
animationPause == false;
}
-(void)animateStop:(NSString*)animationID finished:(BOOL)finished context:(void*)context{
}