Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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
Objective c 捕捉触摸,存储在数组中,然后设置数组内容的动画_Objective C_Arrays_Animation - Fatal编程技术网

Objective c 捕捉触摸,存储在数组中,然后设置数组内容的动画

Objective c 捕捉触摸,存储在数组中,然后设置数组内容的动画,objective-c,arrays,animation,Objective C,Arrays,Animation,我是Objective-C的新手,但通过大量在线信息,我的应用程序取得了一些进展。我的目标是按下记录按钮,然后在视图中移动表示球的图标。我将捕捉阵列中的触球,然后通过单击播放按钮在阵列中的坐标中单步移动来设置触球动画,从而重播球的移动 我正在测试的代码试图逐步遍历数组,并依次为每组坐标设置动画。只有最后一个动画发生。我想我的整个方法可能是错误的。请给我一些帮助,谢谢你的时间 NSMutableArray *yourCGPointsArray = [[NSMutableArray alloc] i

我是Objective-C的新手,但通过大量在线信息,我的应用程序取得了一些进展。我的目标是按下记录按钮,然后在视图中移动表示球的图标。我将捕捉阵列中的触球,然后通过单击播放按钮在阵列中的坐标中单步移动来设置触球动画,从而重播球的移动

我正在测试的代码试图逐步遍历数组,并依次为每组坐标设置动画。只有最后一个动画发生。我想我的整个方法可能是错误的。请给我一些帮助,谢谢你的时间

NSMutableArray *yourCGPointsArray = [[NSMutableArray alloc] init];
[yourCGPointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(300, 001)]];
[yourCGPointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(300, 300)]];
[yourCGPointsArray addObject:[NSValue valueWithCGPoint:CGPointMake(001, 300)]];
int i;
i=0;
while (i < 3) {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    [UIView setAnimationDelay:1.0];
    CGPoint point = [[yourCGPointsArray objectAtIndex:i] CGPointValue];
    player3.center = CGPointMake(point.x , point.y);
    [UIView commitAnimations];
    NSLog (@"i array %d", i);
    NSLog (@"cgpoint x %f", point.x);
    NSLog (@"cgpoint y %f", point.y);
    i = i + 1;

}   
NSMutableArray*yourCGPointsArray=[[NSMutableArray alloc]init];
[yourCGPointsArray addObject:[NSValue-valueWithCGPoint:CGPointMake(300001)];
[yourCGPointsArray addObject:[NSValue-valueWithCGPoint:CGPointMake(300300)];
[yourCGPointsArray addObject:[NSValue-valueWithCGPoint:CGPointMake(001300)];
int i;
i=0;
而(i<3){
[UIView beginAnimations:nil上下文:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelay:1.0];
CGPoint point=[[yourCGPointsArray objectAtIndex:i]CGPointValue];
player3.center=CGPointMake(点x,点y);
[UIView委员会];
NSLog(@“i数组%d”,i);
NSLog(@“cgpoint x%f”,point.x);
NSLog(@“点y%f”,点y);
i=i+1;
}   

}是的,你的方法不正确。现在,您的代码基本上同时触发三个动画——while循环不会等到一个动画完成后再开始下一个动画。相反,您应该启动一个动画,等待它完成,启动下一个,等待它完成,依此类推。可以通过对每个动画使用完成块来启动下一个动画来完成此操作。例如,看看
+animateWithDuration:animations:completion:
。它允许您指定动画的完成块。

谢谢,我来看看。