简体   繁体   中英

Changing tintColor on UIBarButtonItem in UIToolbar causes button to disappear and animate in from left

I'm using Xcode 4.2 to develop an iOS 5 app.

In Storyboard I've got a view with a UIToolbar, and 3 items in it. The last item is a UIBarButtonItem. I want to change the tintColor of this UIBarButtonItem when a user taps it, until what it does is dismissed.

I've made the UIBarButtonItem an outlet in my controller, here's the code:

@property (weak, nonatomic) IBOutlet UIBarButtonItem *upArrowButton;
...
@synthesize upArrowButton = _upArrowButton;

...and I am changing the tintColor like so:

self.upArrowButton.tintColor = [UIColor greenColor];

However when the tintColor changes, the button disappears, and a new one (with the correct new tintColor) animates on screen from the left.

Any idea what mistake I've made?


UPDATE:

I've tracked down the source of the problem, it's because the method where tintColor was changed is called inside an animateWithDuration animations block.

The source of this peculiar behaviour was because I was calling the method that changed the tintColor from within an animateWithDuration animations block. Thus causing the change in tintColor to be 'animated'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM