[英]Stop animateWithDuration
I have a cycle animate in viewController
我在
viewController
有一个循环动画
- (void)moveAnimating
{
[UIView animateWithDuration:2.0f animations:^{
_backgroundView.center = CGPointMake(self.center.x , self.center.y - kMoveDistanceHeight);
} completion:^(BOOL finished) {
if (_backgroundView.animating)
{
[_backgroundView moveAnimating];
}
}];
}
I want stop this animate When the viewController
viewWillDisappear
: 我想停止这个动画当
viewController
viewWillDisappear
:
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
_backgroundView.animating = NO;
[_backgroundView.layer removeAllAnimations];
}
Because the animation is conflict with dismissViewcontrollerAnimation
. 因为动画与
dismissViewcontrollerAnimation
冲突。
Question: 题:
[_backgroundView.layer removeAllAnimations];
not work... 不行...
How to stop the animation? 如何停止动画?
Help me,thanks. 帮帮我,谢谢。
You are canceling animations correctly: 您正在取消动画:
[_backgroundView.layer removeAllAnimations];
But you might forget about importing QuartzCore.h: 但是你可能会忘记导入QuartzCore.h:
#import <QuartzCore/QuartzCore.h>
If it doesn't help try this: 如果没有帮助尝试这个:
[CATransaction begin];
[_backgroundView.layer removeAllAnimations];
[CATransaction commit];
If it doesn't help try to add this line to the code above: 如果它没有帮助尝试将此行添加到上面的代码:
[CATransaction flush];
Te solution from @KlimczakM didn't work for me. 来自@KlimczakM的解决方案对我不起作用。
I'm running an 'animateWithDuration' block that moves and image, and I use the next code to pause and resume the animation: 我正在运行一个'animateWithDuration'块来移动和成像,我使用下一个代码来暂停和恢复动画:
-(void)pauseLayer:(CALayer*)layer {
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
}
-(void)resumeLayer:(CALayer*)layer {
CFTimeInterval pausedTime = [layer timeOffset];
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
layer.beginTime = timeSincePause;
}
This is from the Apple Documentation at this link . 这是来自此链接的Apple文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.