没有使用完成块,可以在UIView上做多个animation

这只是为了说明问题,简单的问题,我的具体代码要复杂得多。

比方说,我有UILabel是左上angular的位置。
有了这个代码,我会把它移到右上angular:

// labelMove is moved to TOP RIGHT [UIView animateWithDuration:1.0f delay:2.0f options:UIViewAnimationOptionCurveEaseOut animations:^ { labelMove.center = CGPointMake(250.0f, 40.0f); } completion:nil]; 

如果我有这个代码:

 // labelMove is moved to TOP RIGHT [UIView animateWithDuration:1.0f delay:2.0f options:UIViewAnimationOptionCurveEaseOut animations:^ { labelMove.center = CGPointMake(250.0f, 40.0f); } completion:nil]; // labelMove is moved to BOTTOM RIGHT [UIView animateWithDuration:1.0f delay:2.0f options:UIViewAnimationOptionCurveEaseOut animations:^ { labelMove.center = CGPointMake(250.0f, 450.0f); } completion:nil]; 

它不会从左上angular开始,而是从右上angular开始,然后是右下angular。
不知何故,第一个animation不是animation,只有最后一个。
我不明白为什么,但那不是那么重要。
我可以把第二个完成:第一个块,然后它将工作。
像这样的代码。

 // labelMove is moved to TOP RIGHT [UIView animateWithDuration:1.0f delay:2.0f options:UIViewAnimationOptionCurveEaseOut animations:^ { labelMove.center = CGPointMake(250.0f, 40.0f); } completion:^(BOOL finished){ // labelMove is moved to BOTTOM RIGHT [UIView animateWithDuration:1.0f delay:2.0f options:UIViewAnimationOptionCurveEaseOut animations:^ { labelMove.center = CGPointMake(250.0f, 450.0f); } completion:nil]; }]; 


是否可以从最后一个代码生效,但不以任何方式使用完成块。
这对我来说非常重要。
我尝试使用CABasicAnimation,但不能这样做,也许有更多经验的人可以吗?
我相信肯定有办法,但我无法弄清楚。

没有完成块的代码不起作用,因为您试图在完全相同的时间点将标签设置为两个不同的位置。 这实际上是不可能的。

在完成块内运行第二个animation时,将第一个animation之后运行,而不是同时运行 。 为了达到同样的效果,请发送第二个animation,以便在第一个animation之后执行。 由于第一个animation将需要2.0延迟+ 1.0持续时间= 3.0秒完成,3.0秒后分派。 见下文。

 // labelMove is moved to TOP RIGHT [UIView animateWithDuration:1.0f delay:2.0f options:UIViewAnimationOptionCurveEaseOut animations:^ { labelMove.center = CGPointMake(250.0f, 40.0f); } completion:nil]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ // labelMove is moved to BOTTOM RIGHT [UIView animateWithDuration:1.0f delay:2.0f options:UIViewAnimationOptionCurveEaseOut animations:^ { labelMove.center = CGPointMake(250.0f, 450.0f); } completion:nil]; }); 

只要知道,不使用完成块,你不能保证第一个animation是真正完成animation。 在实践中,这应该通常很好。

您可以使用CAKeyframeAnimation,并使用这两点创buildpath。

以下是苹果的一些例子:

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Animation_Types_Timing/Articles/PropertyAnimations.html