简体   繁体   中英

Objective-C NSArray troubles

Ok I am trying to deal a deck of cards at certain positions, but I am stuck at a spot. I am only dealing one less than the max. I am trying to deal to every spot in the index of the nsarray.

- (CGPoint)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(0, 0)],
                         [NSValue valueWithCGPoint:CGPointMake(0, 0)],
                         [NSValue valueWithCGPoint:CGPointMake(0, 0)],
                         [NSValue valueWithCGPoint:CGPointMake(0, 0)],
                         [NSValue valueWithCGPoint:CGPointMake(10,   50)],


                         nil];


    for(int i=0; i<5; i++) {
        NSValue *value = [position objectAtIndex:i];
        CGPoint point = [value CGPointValue];
        NSLog(@"%@",NSStringFromCGPoint(point));

        self.center = point;


    }

}

I am dealing the card at 10,50 and not dealing the card at previous positions such as 0,0. This is probably easy to solve, but I can't seem to remember how to fix this. Please help me. Also, note that I am still somewhat new to objective c so you may have to dumb this down if you solve this lol.

The problem is that you are setting the cards position 5 times without doing any animation or giving the card object a chance to be redrawn in between changing it's position. iOS doesn't actually position the card until the run loop gets a chance to fire. There are a number of possible solutions, but you should probably look into adding an animation block inside your loop so that the movement is queued for the the display.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM