CATransitionFade not working on newly added subviews
- by David Liu
For some reason, fading in new buttons using CATransition isn't working for me when it's a newly added button. The fade animation, however, is working on existing subviews.
Code:
// Add new button.
CATransition *animation = [CATransition animation];
[animation setDuration:0.5];
[animation setType:kCATransitionFade];
[[button layer] addAnimation:animation forKey:@"fadeIn"];
[self.view addSubview:button];
// Enable previous button (Enabling fades in different type of background)
if(toolbar.buttons.count != 0){
UIButton * prevButton = [toolbar.buttons objectAtIndex:(toolbar.buttons.count - 1)];
prevButton.enabled = YES;
[[prevButton layer] addAnimation:animation forKey:@"fadeIn"];
}