Fade UIBarButtonItem when changing

When I change my UIBarButtonItems, they change dramatically, unlike the default, which gives a nice but quick fade animation. You can see this when you can switch between view managers, for example, the back button will fade out. How can I simulate the same effect?

+7
ios objective-c iphone ipad uibarbuttonitem
source share
2 answers

Update - based on this answer - stack overflow.site/questions/522934 / ...

It looks like you will need to do something like this so that the button itself disappears.

[self.navigationItem setRightBarButtonItem:nil animated:YES]; 

And do something like this to make it disappear in

  [self.navigationItem setRightBarButtonItem:myButton animated:YES]; 

Otherwise, if you want more control over the properties of the animation, you need to create your own view, which I consider.

EDIT: I just confirmed that you can change the custom look of the UIBarButtonItem using this.

As a test, I created a simple project and dropped the UIBarButtonItem into the navigation bar. I created an output for the view controller. In viewDidLoad on the view controller, I set up a custom view

 -(void)viewDidLoad{ [super viewDidLoad]; UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0,0,40,40)]; lbl.text = @"test"; UIView *customView = [[UIView alloc]initWithFrame:CGRectMake(0,0,40,40)]; [customView addSubview:lbl]; self.barButtonItem.customView = customView; } 

As a test in viewDidAppear, I animated it

  -(void)viewDidAppear:(BOOL)animated { [UIView animateWithDuration:3.0 delay:3.0 options:UIViewAnimationOptionCurveEaseOut animations:^{ self.barButtonItem.customView.alpha = 0; } completion:^(BOOL finished) { NSLog(@"animation complete"); }]; 

EDIT: Here's a link to the apple documentation for a full explanation of the UIView animation. https://developer.apple.com/library/ios/documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html

+12
source share

You may need to create a custom panel element using a view or image, and then animate the properties of the view, as digitalHound shows.

-one
source share

All Articles