链接动画:第一个是即时的

时间:2012-10-29 16:15:13

标签: ios animation uiviewanimation

以下功能应该A.使视图变大B.等待5秒钟,然后再缩小它。问题是A会立即发生而不是两秒钟。

- (void) showAndHide {
CGRect r = self.frame;
float right = r.origin.x + r.size.width, h = r.size.height, y = r.origin.y;

[UIView animateWithDuration:2
                      delay:0
                    options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction
                 animations:^{
                     self.frame = CGRectMake(right - 400, y, 400, h);
                     [UIView animateWithDuration:2
                                           delay:5
                                         options: UIViewAnimationOptionOverrideInheritedCurve |
                      UIViewAnimationOptionCurveLinear |
                      UIViewAnimationOptionOverrideInheritedDuration
                                      animations:^{
                                          self.frame = CGRectMake(right - 40, y, 40, h);
                                      }
                                      completion:nil];

                 }
                 completion:nil];

}

可能导致这种情况的原因是什么?提前谢谢!

1 个答案:

答案 0 :(得分:0)

将第二个动画放在第一个动画的完成处理程序中:

- (void) showAndHide {
CGRect r = self.frame;
float right = r.origin.x + r.size.width, h = r.size.height, y = r.origin.y;

[UIView animateWithDuration:2
                      delay:0
                    options:UIViewAnimationOptionCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction
                 animations:^{
                     self.frame = CGRectMake(right - 400, y, 400, h);
                 }
                 completion:^{
                 [UIView animateWithDuration:2
                                       delay:5
                                     options: UIViewAnimationOptionOverrideInheritedCurve | UIViewAnimationOptionCurveLinear | UIViewAnimationOptionOverrideInheritedDuration
                                      animations:^{
                                          self.frame = CGRectMake(right - 40, y, 40, h);
                                      }
                                      completion:NULL];
                 }];
}

您的方法存在的问题是,两个动画同时排队。如果你想坚持你的代码,我认为将UIViewAnimationOptionBeginFromCurrentState添加到第二个动画的选项可能也会解决你的问题。虽然不太确定。