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

后端 未结 2 1597
轻奢々
轻奢々 2021-01-13 12:08

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 s

2条回答
  •  抹茶落季
    2021-01-13 12:37

    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];
    

提交回复
热议问题