Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在完成之前启动UIView动画?_Iphone_Objective C_Ios_Animation - Fatal编程技术网

Iphone 在完成之前启动UIView动画?

Iphone 在完成之前启动UIView动画?,iphone,objective-c,ios,animation,Iphone,Objective C,Ios,Animation,我正在使用[UIView animateWithDuration:…]为UIImageView视图的序列设置动画。像这样: [UIView animateWithDuration:1.0 animations:^{ imageView.frame = newImageRectPosition; }completion:^(BOOL finished){ //animate next UIImageView }]; 我需要动画'下一个UIImageView'不是在完成。我需要在上一个动

我正在使用
[UIView animateWithDuration:…]
UIImageView
视图的序列设置动画。像这样:

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

我需要动画'下一个UIImageView'不是在完成。我需要在上一个动画的中间,而不是完成时,为“下一个UIImageView”设置动画。可以这样做吗?

您可以设置两个UIView动画块,其中一个延迟为第一个动画持续时间的一半:

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

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

您可以使用许多选项来实现所追求的效果。我想到的是计时器的使用

使用触发间隔为动画一半的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.5sRelated的延迟开始另一个动画:对接受
延迟的动画块使用NSTimer似乎有点愚蠢。只需延迟使用视图动画…视情况而定;假设您有n个需要运行的动画。通过指定带有延迟的动画,您必须同时提交所有动画,这对于大量的n可能是一个逻辑噩梦,具体取决于动画时间及其各自的延迟。使用计时器,可以在需要时提交动画。让计时器定期重复以提交动画块可以更轻松地管理时间和延迟。但是我同意,在这种情况下,只有2个动画块,延迟将是最简单和最合适的。我同意你给出的例子:)这种方法有效,但是,我认为使用animateKeyframesWithDuration是一种更好的方法。