Cocoa touch 如何暂停和恢复UIView动画(无块动画)?
如何暂停和恢复UIView动画?(不带块动画)Cocoa touch 如何暂停和恢复UIView动画(无块动画)?,cocoa-touch,uiview,uiviewanimation,Cocoa Touch,Uiview,Uiviewanimation,如何暂停和恢复UIView动画?(不带块动画) 我当时最难弄明白这一点,因此下面是我的资料来源,介绍如何做到这一点。如何暂停和恢复UIView动画: 这将介绍如何在没有块动画的情况下执行上述操作。(人们仍然希望支持3.0及更高版本) 这仅允许在动画达到设定位置后暂停。对于如何在动画中间暂停动画,我建议使用这样的计算器: CALayer* myLayer = [self.myUIView.layer presentationLayer]; CGRect frameStop = myLayer.fr
我当时最难弄明白这一点,因此下面是我的资料来源,介绍如何做到这一点。如何暂停和恢复UIView动画: 这将介绍如何在没有块动画的情况下执行上述操作。(人们仍然希望支持3.0及更高版本) 这仅允许在动画达到设定位置后暂停。对于如何在动画中间暂停动画,我建议使用这样的计算器:
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{
}
animationPause==false代码>和animationPause==true代码>是比较,不做任何事情。您可能想分配值,但恐怕您没有。您将一个比较替换为另一个比较<代码>bicyclePad.animationPause==false代码>仍然是一个比较,结果被丢弃。您需要bicyclePad.animationPause=false代码>。注意==
与=
的对比。好吧。我不明白你的第一句话。是的,这个密码大约有2年了。谢谢你指出这一点@黑暗的