Custom navigationItem animation

佐手、 提交于 2019-12-23 04:48:14

问题


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:


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


来源:https://stackoverflow.com/questions/6136067/custom-navigationitem-animation

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