2012-10-22 111 views
1

我正在使用[UIView animateWithDuration:...]获得动画序列UIImageView的意见。像这样:完成之前开始动画UIView?

[UIView animateWithDuration:1.0 animations:^{ 
    imageView.frame = newImageRectPosition; 
}completion:^(BOOL finished){ 
//animate next UIImageView 
}]; 

我需要动画“下一个UIImageView”没有完成。我需要在前一个动画的中间动画'next UIImageView',而不是完成。是否有可能这样做?

+1

开始另一个动画与0.5秒 – Felix

+0

相关的延迟:http://stackoverflow.com/a/27609589/870028 – Johnny

回答

2

您可以创建了两个UIView的动画块,一个具有第一动画的1/2时间的延迟:

[UIView animateWithDuration:1.0 
       animations:^{ ... } 
       completion:^(BOOL finished){ ... } 
]; 

[UIView animateWithDuration:1.0 
         delay:0.5 
        options:UIViewAnimationCurveLinear 
       animations:^{ ... } 
       completion:^(BOOL finished) { ... } 
]; 
+1

感谢,工作 –

+0

这样的工作,但是,我认为,使用animateKeyframesWithDuration是一个更好的办法。 – Johnny

0

有你可以用它来实现你后的效果很多选择。想到的一点是定时器的使用。

使用一个NSTimer,其间隔为动画的一半,并让计时器触发另一个动画。只要这两个动画不会互相干扰,你应该没问题。

一个例子是像这样:

NSTimer* timer; 
// Modify to your uses if so required (i.e. repeating, more than 2 animations etc...) 
timer = [NSTimer scheduledTimerWithTimeInterval:animationTime/2 target:self selector:@selector(runAnimation) userInfo:nil repeats:NO]; 

[UIView animateWithDuration:animationTime animations:^{ 
    imageView.frame = newImageRectPosition; 
} completion:nil]; 

- (void)runAnimation 
{ 
    // 2nd animation required 
    [UIView animateWithDuration:animationTime animations:^{ 
     imageView.frame = newImageRectPosition; 
    } completion:nil]; 
} 

具有定时功能,这可能扩大,如果你需要做两个以上的动画,而这一切都粘在一起如果以后需要改变动画时间上。

+0

对于接受“延迟”的动画块使用NSTimer似乎有点愚蠢。只是延迟使用视图动画... – runmad

+0

取决于情况;假设你有n个需要运行的动画。通过延迟指定动画,您必须同时提交所有动画,而这对于大量的n来说可能是一个后勤噩梦,具体取决于动画时间和它们各自的延迟。 使用定时器,您可以在需要时提交动画。让计时器定期重复提交动画块,可以更轻松地管理时间和延迟。 我同意,在这种情况下,只有2个动画块,延迟将是最简单和最合适的。 – WDUK

+0

我同意你给出的例子:) – runmad

相关问题