0
votes

I`m wondering if is possible to write different UIView animation at the same time. I trying to animate two Apple style flip counters using sprite animation simultaneously. Each flip counter has his own animation. The problem is that the second flip counter start to run when the first counter finish.

EDITED Twice: Here is the code: https://dl.dropbox.com/u/1348024/MultipleFlipCounters.zip

There are two simple classes “FlipCounterView.m” and “CounterViewController”. Tapping the screen “CounterViewController” will start the animation. Thanks!

EDITED:

Relevant code added.

Apple style flip counter sprite animation is done FlipCounterView class.

- (void)viewDidLoad{
[super viewDidLoad];
flipCounter1 = [[FlipCounterView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[flipCounter1 add:10];
[self.view addSubview:flipCounter1];

flipCounter2 = [[FlipCounterView alloc] initWithFrame:CGRectMake(0, 120, 200, 200)];
[flipCounter2 add:10];
[self.view addSubview:flipCounter2];
}

Tapping screen:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

[UIView animateWithDuration:0.5
                     animations:^{
                         //this method made an sprite animation on flipCounter1
                         [flipCounter1 distributedAdd:150 overSeconds:0 withNumberOfIterations:3];
                     }];

[UIView animateWithDuration:0.5
                     animations:^{
                         //this method made an sprite animation on flipCounter2
                         [flipCounter2 distributedAdd:150 overSeconds:0 withNumberOfIterations:3];
                     }];

}

2
Please include relevant CCDs in your question -- nobody wants to download your entire project.Caleb
Oh and BTW, your code crashesRavi

2 Answers

0
votes

Your code crashes, but give this a try after fixing the crash:

- (void)animateNow1
{
    [UIView animateWithDuration:0.5
                     animations:^{
                         [flipCounter1 distributedAdd:150 overSeconds:0 withNumberOfIterations:3];
                     }];

}
- (void)animateNow2
{
    [UIView animateWithDuration:0.5
                     animations:^{
                         [flipCounter2 distributedAdd:150 overSeconds:0 withNumberOfIterations:3];
                     }];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self performSelector:@selector(animateNow1) withObject:nil afterDelay:0.00];
    [self performSelector:@selector(animateNow2) withObject:nil afterDelay:0.00];
}    
0
votes

The crash in your code seems to be unrelated to the animation (Xcode 4.5.1), and if you want both animations performing simultaneously you can just do this in one animation block (since the animations attributes are the same).

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [UIView animateWithDuration:0.5 animations:^{
        [flipCounter1 distributedAdd:150 overSeconds:0 withNumberOfIterations:3];
        [flipCounter2 distributedAdd:150 overSeconds:0 withNumberOfIterations:3];
    }];
}