I have a method which can create and animate view
- (void) draw {
UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(57, 353, 350, 80)];
[self.view addSubview:label];
[UIView animateWithDuration:3
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
[UIView animateWithDuration:2
delay:0
options:UIViewAnimationOptionCurveLinear
animations:^{
label.alpha = 0;
} completion:^(BOOL finished) {
[self.view willRemoveSubview:label];
}];
} completion:^(BOOL finished) {
}];
}
This method called when button was clicked. But if I click fast, the new views appear without waiting when the previous has finished. I want to create a queue of methods, like, when I tap on button, the new event is pushing to the queue, and all events are waiting when the previous one is finished, to start. Maybe I can do this with NSOperationQueue or GCD ?
Why are you nesting the animateWithDuration:... call? I believe you can eliminate some of that complexity by only having a single call to animateWithDuration:...
To answer your actual question, you can use a simple queue made with a NSMutableArray. You can encapsulate your animation call as an object (either full custom or simply as a block or an NSInvocation) and push that object into the array. In the scenario you describe everything is running on the main thread, so you don't have to do any synchronization. Simply have a flag (isRunning) that you set when you start animating, and on completion try to see if there's another animation to start. Otherwise set the flag to false.
That should avoid any GCD calls.