I am trying to animate a UIToolbar's tintColor property, to change it from one tintColor to another.
Here is the code I am trying. Unfortunately, the change occurs immediately and does not fade from green to blue. This is strange because I know Apple fades and "pulses" toolbar tint colors when tethering or on a phone call. So why doesn't this work?
// set initial tint color
myBottomToolBar.tintColor = [UIColor colorWithRed:0.15 green:0.95 blue:0.15 alpha:0.6];
//animation stuff
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.95];
[UIView setAnimationDelegate:self];
//thing to animate
myBottomToolBar.tintColor = [UIColor colorWithRed:0.15 green:0.35 blue:0.45 alpha:0.6];
//animation stuff
[UIView commitAnimations];
The tint color in not animatable through public APIs. You can work around this by manually changing the tint color on a timer. You would have to interpolate the intermediate color levels.
Each UIView
has a tintAdjustmentMode:
The first non-default tint adjustment mode value in the view’s hierarchy, ascending from and starting with the view itself.
When this property’s value is dimmed, the value of the tintColor property is modified to provide a dimmed appearance.
For example, if you need to dim the current tintColor (dim = grey color) just use the code below:
// Assuming tintAdjustmentMode is set to .automatic
UIView.animate(withDuration: 0.5) {
yourView.tintAdjustmentMode = .dimmed
}
This will animate the tintColor to grey and will dim it.
If you want to animate the tintColor to your own custom color:
// Make sure it is set to normal and not automatic
yourView.tintAdjustmentMode = .normal
UIView.animate(withDuration: 0.5) {
yourView.tintColor = .black
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With