Since selected
is not an animatable property, that won't work (as you've found out). My solution would be to have the selected state of the btn be in a separate UIImageView directly below the button in the exact same location. Then in the action for tapping the button:
- (void) tapButton:(UIButton *)btn {
btn.alpha = 0;
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelegate:[UIApplication sharedApplication]];
[UIView setAnimationDidStopSelector:@selector(endIgnoringInteractionEvents)];
btn.alpha = 1;
[UIView commitAnimations];
}
Note I also added the begin/endIgnoringInteractionEvents
calls so the user can't tap on the button while it's fading back to its normal state. If you want to allow that, replace the begin/end
calls with [UIView setAnimationBeginsFromCurrentState];
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…