I am trying to show an animated n number of level.
There is n number of levels under UIStackView.
What I want: Using animation
- First, change the label 4's background color
- Second, change the label 3's background color
- Third, change the label 7's background color
.......
- nth, change the label background color
What is the problems: Change all background color instantly without delaying.
@property (nonatomic, strong) IBOutletCollection(UILabel) NSArray *lblArray;
-(void)animationTestIntoLoop {
__block NSMutableArray* animationBlocks = [NSMutableArray new];
typedef void(^animationBlock)(BOOL);
// getNextAnimation
// removes the first block in the queue and returns it
animationBlock (^getNextAnimation)(void) = ^{
if ([animationBlocks count] > 0){
animationBlock block = (animationBlock)[animationBlocks objectAtIndex:0];
[animationBlocks removeObjectAtIndex:0];
return block;
} else {
return ^(BOOL finished){
animationBlocks = nil;
};
}
};
for (UILabel *label in self.lblArray) {
[animationBlocks addObject:^(BOOL finished){
[UIView animateWithDuration:3 delay:1.0 options:UIViewAnimationOptionCurveLinear animations:^{
//my first set of animations
label.backgroundColor = [UIColor redColor];
} completion: getNextAnimation()];
}];
}
getNextAnimation()(YES);
}