嵌套的UIView animateWithDuration:delay:options:animate:完成不延迟

时间:2013-08-08 19:15:44

标签: objective-c uikit objective-c-blocks uiviewanimation

// Animate moving the cards into position
    [UIView animateWithDuration:0.5
                          delay:0.0
                        options:UIViewAnimationOptionCurveLinear
                     animations: ^{ card.frame = cardFrame; }
                     completion: ^ (BOOL finished) {
                         if (finished) {
                             [UIView animateWithDuration:1.0
                                                   delay:3.0
                                                 options:UIViewAnimationOptionTransitionFlipFromRight
                                              animations: ^ { card.image = [UIImage imageNamed:@"imgBack.png"]; }
                                              completion:NULL];
             }
                     }];
  

由于某种原因,第二次延迟不会延迟。动画会立即继续提供帮助吗?

1 个答案:

答案 0 :(得分:2)

您实际遇到的问题与嵌套无关。 UIImageView根本无法为setImage:属性设置动画,因此代码会在到达时立即执行。

如果你可以简单地延迟设置图像属性,那么继续使用:

double delayInSeconds = 2.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    card.image = newImage;
});

如果您想要更改图像的动画,您可能需要查看CATransition,并对图像视图中更改的图像应用过渡效果。