如何暂停和恢复 UIView 动画(没有块动画)? [英] How to pause and resume UIView Animation (without Block Animation)?
本文介绍了如何暂停和恢复 UIView 动画(没有块动画)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何暂停和恢复 UIView 动画?(无块动画)
How do you pause and resume UIView Animations? (without block animations)
我最难解决这个问题,所以下面是我的资料来源.
I was having the hardest time figuring this out, so here is my source below on how to do it.
推荐答案
如何暂停和恢复 UIView 动画:
How to pause and resume UIView Animations:
这将介绍如何在没有块动画的情况下执行上述操作.(人们仍然希望支持 3.0 及更高版本).
This will cover how to do the above without block animations. (People do still wish to support 3.0 and up).
这仅允许在动画到达设定位置后暂停.关于如何在动画中间暂停动画,我建议使用 CALayer:
This only allows for pausing once the animation has met the set location. For how to pause an animation in the middle of an animation, i suggest using CALayers as such:
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{
}
这篇关于如何暂停和恢复 UIView 动画(没有块动画)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文