UIView动画完成块立即执行

时间:2015-06-19 12:36:18

标签: ios objective-c uiview

-(void)methodXXXX {

       [UIView animateWithDuration:11 animations:^{
               //...some animation changes...
            } completion:^(BOOL finished) {
                  [_fallBtn removeFromSuperview];
                  _fallBtn = nil;
            }
       }];
}

我在-viewDidAppear调用此方法,而直接调用完成块

为什么呢?我错过了什么奇怪的事情?

我发现了另外一件事:

CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
    pathAnimation.calculationMode = kCAAnimationPaced;
    pathAnimation.fillMode = kCAFillModeForwards;
    pathAnimation.removedOnCompletion = YES; //If set YES, it will directly call -animationDidStop method; if NO, the animation execute while never call -animationDidStop
    pathAnimation.duration = 10;
    pathAnimation.delegate = self; //here I implement the -animationDidStop method

2 个答案:

答案 0 :(得分:2)

使用以下代码。

-(void)viewDidAppear:(BOOL)animated {
         [self performSelector:@selector(methodXXXX) withObject:nil afterDelay:0.1f];
    }

-(void)methodXXXX {

    [UIView animateWithDuration:11 animations:^
            //...some animation changes...
        } completion:^(BOOL finished) {
            [_fallBtn removeFromSuperview];
            _fallBtn = nil;
    }];
}

答案 1 :(得分:0)

[UIView animateWithDuration:11 delay:"add some delay and try" options:0 animations:^{

} completion:^(BOOL finished) {

}];