停止animateWithDuration

时间:2015-01-29 07:49:18

标签: ios uianimation

我在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];
        }
    }];
}

我希望在viewController viewWillDisappear

时停止此动画
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    _backgroundView.animating = NO;
    [_backgroundView.layer removeAllAnimations];
}

因为动画与dismissViewcontrollerAnimation冲突。

问题:

[_backgroundView.layer removeAllAnimations];

不行......

如何停止动画?

帮助我,谢谢。

1 个答案:

答案 0 :(得分:2)

您正在取消动画:

[_backgroundView.layer removeAllAnimations];

但是你可能会忘记导入QuartzCore.h:

#import <QuartzCore/QuartzCore.h>

如果没有帮助尝试这个:

[CATransaction begin];
[_backgroundView.layer removeAllAnimations];
[CATransaction commit];

如果没有帮助,请尝试将此行添加到上面的代码中:

[CATransaction flush];