Reputation: 3
On iOS7, we can changing navigation bar's color by
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
But this method has a fade animation when changing the barTintColor, So does anynone know how to prevent this animation and change the color immediately?
To be more specific, I wrote a test program whose window's root controller is navigationController. And in the navigationController, there is a view controller with 3 buttons. 3 buttons all bind to the following action:
- (void)onClick:(id)sender
{
UIColor *color = nil;
if (sender == self.redButton)
{
color = [UIColor redColor];
}
else if (sender == self.blueButton)
{
color = [UIColor blueColor];
}
else if (sender == self.blackButton)
{
color = [UIColor blackColor];
}
self.navigationController.navigationBar.barTintColor = color
// [UIView animateWithDuration:0 animations:^{
// self.navigationController.navigationBar.barTintColor = color;
// }];
// [CATransaction begin];
// [CATransaction setDisableActions:YES];
// self.navigationController.navigationBar.barTintColor = color;
// [CATransaction commit];
}
Both changing the animation duration to 0 or using [CATransaction setDisableActions:YES]
doesn't work, the animation still exists.
Hope someone can help, thank you!
Upvotes: 0
Views: 1362
Reputation: 1405
Set translucent
property on the UINavigationBar
to NO
, then reset it after the bar tint is changed
self.navigationBar.translucent = NO;
self.navigationBar.barTintColor = [UIColor magentaColor];
self.navigationBar.translucent = YES;
Upvotes: 1
Reputation: 9355
Try setting barTintColor to nil before setting it again.
self.navigationController.navigationBar.barTintColor = nil;
self.navigationController.navigationBar.barTintColor = color;
I had a similar problem, and it fixed it for me. Hope it helps.
Upvotes: 3
Reputation: 15442
You need to disable the implicit animation. You can do this as follows:
[CATransaction begin];
[CATransaction setDisableActions: YES];
self.navigationItem.leftBarButtonItem.tintColor = [UIColor colorWithRed:125.0/255.0 green:90.0/255.0 blue:146.0/255.0 alpha:1];
[CATransaction commit];
This technique works for any implicit animation. An implicit animation is an animation that's created for you by iOS when you change an animatable property. See here for more information:
Upvotes: 1
Reputation: 2818
Try with
[UIView animateWithDuration:0 animations:^{
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
}];
Upvotes: -1