Is it possible to use Core Animation to fade out a UIBarButtonItem?

感情迁移 提交于 2019-12-19 07:56:35

问题


I'm curious, is it possible to somehow intertwine Core Animation to give a "fade out" of a UIBarButtonItem? I have a tableView which I represent with two different data sources. Once a particular data source gets triggered, I'd like to fade out the current UIToolBar options and fade in new ones.

Thanks for pointing me in the right direction.


回答1:


If you really are using a UIToolbar (note the lower-case "b") and not a UINavigationBar, there is a very easy way to change the buttons and have the transition automatically fade without dropping to Core Animation.

If you're using Interface Builder, you'll need a reference to the toolbar in your code. Create an IBOutlet property and link the toolbar to it in IB:

@property (nonatomic, retain) IBOutlet UIToolbar *toolbar;

This will allow you to reference the UIToolbar as self.toolbar. Then, create your new buttons and add them to an NSArray and pass this to the -[UIToolbar setItems:animated:] method as follows:

UIBarButtonItem *newItem = [[[UIBarButtonItem alloc] 
                                initWithBarButtonSystemItem:UIBarButtonSystemItemDone 
                                target:self 
                                action:@selector(handleTap:)] autorelease];
NSArray *newButtons = [NSArray arrayWithObjects:newItem, nil];
[self.toolbar setItems:newButtons animated:YES];



回答2:


I don't believe there's a way to control the alpha on a UIBarButtonItem, but the UIToolbar class already has a method to support what you're trying to do: -setItems:animated:.



来源:https://stackoverflow.com/questions/815784/is-it-possible-to-use-core-animation-to-fade-out-a-uibarbuttonitem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!