I need to call the function animate dealing to player each time the for loop runs.
-(void)animateDealingToPlayer:(Player *)player withDelay:(NSTimeInterval)delay
{
self.frame = CGRectMake(-100.0f, -100.0f, CardWidth, CardHeight);
self.transform = CGAffineTransformMakeRotation(M_PI);
NSArray *position = [NSArray arrayWithObjects:
[NSValue valueWithCGPoint:CGPointMake(100, 100)],
[NSValue valueWithCGPoint:CGPointMake(0, 0)],
[NSValue valueWithCGPoint:CGPointMake(0, 0)],
[NSValue valueWithCGPoint:CGPointMake(200, 100)],
[NSValue valueWithCGPoint:CGPointMake(200, 100)],
nil];
for(int i=0; i<6; i++) {
NSValue *value = [position objectAtIndex:i];
CGPoint point = [value CGPointValue];
NSLog(@"%@",NSStringFromCGPoint(point));
_angle = [self angleForPlayer:player];
[UIView animateWithDuration:0.2f
delay:delay
options:UIViewAnimationOptionCurveEaseOut
animations:^
{
self.center = point;
self.transform = CGAffineTransformMakeRotation(_angle);
}
completion:nil];
Right now it is rewriting self.center over and over until it gives out the 5th object index instead of calling all of the index numbers individually.For example instead of dealing cards at all of the points it is dealing only at (200,100). I need some way to call animaitedealingwithplayer each time so it will deal at all the points,but how do I do that? Will appreciate any help I can get.
The problem is that you are creating multiple animation blocks that apply to a single view element, and you are applying these all at once.
Instead, you can cause the animation block to trigger another animation on completion.
There is an example in the Apple View Programming Documentation: “Listing 4-2 shows an example of an animation block that uses a completion handler to initiate a new animation after the first one finishes“
I’m posting the example here so you can get a feel for it, but go read the documentation!:
In your example, you should probably (in pseudocode):