Custom navigationItem animation

2019-06-09 20:52发布

I want a custom animation on the leftBarButtonItem:

 UIBarButtonItem *menuButton = [[UIBarButtonItem alloc]
                               initWithTitle:@"Menu" 
                               style:UIBarButtonItemStyleBordered 
                               target:self 
                               action:@selector(onMenuButtonTouch)];
viewController.navigationItem.leftBarButtonItem = menuButton;

My UINavigationController pushes and pops views with a custom animation so the leftBarButtonItem doesn't have any animations at the moment.

[self.navigationController pushViewController:myViewController animated:NO];
[UIView animateWithDuration:...

-

First I changed a property the see if it is animated but that didn't work. Then I tried to set the property before the animation starts but that didn't work either. It takes absolutely no effect.

Is there a way to animate something like this for example?

self.navigationController.navigationItem.leftBarButtonItem.width = 10;

or

self.navigationController.navigationItem.leftBarButtonItem.customView.alpha = 0;

1条回答
混吃等死
2楼-- · 2019-06-09 21:04

UIBarButtonItems are not a subclass of UIView so you can't apply animations on them but customView is a UIView object so you can animate it.

[UIView animateWithDuration:1.0
                 animations:^{
                     self.navigationItem.rightBarButtonItem.customView.alpha = 0;
                 }];
查看更多
登录 后发表回答