Ios 如何设置uiimageview的动画并停止其余过程

Ios 如何设置uiimageview的动画并停止其余过程,ios,iphone,Ios,Iphone,我正在做一个应用程序。我正在为uiimageview做动画,以显示不同的图像,如下所示 UIImageView * fearthersanimate = nil; [fearthersanimate setCenter:sender.center]; fearthersanimate = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 120,200)]; [fearthersanimate setCent

我正在做一个应用程序。我正在为uiimageview做动画,以显示不同的图像,如下所示

    UIImageView * fearthersanimate = nil;
    [fearthersanimate setCenter:sender.center];

    fearthersanimate = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 120,200)];
    [fearthersanimate setCenter:CGPointMake(sender.center.x, sender.center.y)];
    fearthersanimate .animationImages = [NSArray arrayWithObjects:
                                         [UIImage imageNamed:@"water_can_1.png"],
                                         [UIImage imageNamed:@"water_can_2.png"],[UIImage imageNamed:@"water_can_3.png"],
                                         [UIImage imageNamed:@"water_can_4.png"],[UIImage imageNamed:@"water_can_5.png"],
                                         [UIImage imageNamed:@"water_can_6.png"],[UIImage imageNamed:@"water_can_7.png"],
                                         [UIImage imageNamed:@"water_can_8.png"],
                                         nil];
    fearthersanimate.animationDuration =  1.0f;
    fearthersanimate.animationRepeatCount = 1;
    [self.view addSubview: fearthersanimate];
    [fearthersanimate startAnimating];

但剩余的操作将在此动画结束之前开始。但我需要先执行此动画,直到需要停止剩余的过程。

您可以使用UIView动画块。例如:

[UIView animateWithDuration:0.5 animations:^{

} completion:^(BOOL finished) {

}];

将剩余的进程放在完成块中。

这些动画是异步执行的,因此您只需要用异步对抗异步

dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(feathersanimate.animationDuration * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    // Remaining logic
});

您可以在其他方法中调用其余操作,并在设置图像动画时间的相同延迟后调用它。 下面是一行代码,您可以通过它在一段时间间隔后调用其他方法

 [self performSelector:@selector(restOfOperations) withObject:nil afterDelay:1.0];  
//restOfOperations方法定义/实现

  -(void)restOfOperations
  {
    //your code you want to perform after image animation
  }