how can I animate the UINavigationBar background change on UIViewController push?

℡╲_俬逩灬. 提交于 2019-12-01 01:47:23

问题


My app uses two different backgrounds for the UINavigationBar to indicate to the user what level in the hierarchy they're at. When I push a UIViewController that needs the second background it lacks animation, the background changes immediately as soon as the UIViewController is pushed. How can I animate this so that the background change fades as the view is being changed?


回答1:


I know this is an old thread, but this worked for me:

CATransition *transition = [CATransition animation];
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
transition.type = kCATransitionFade;
transition.duration = 0.5;

[self.navigationController.navigationBar.layer addAnimation:transition forKey:nil];
[self.navigationController.navigationBar setBackgroundImage:[[UIImage imageNamed:@"navigationbar.png"]resizableImageWithCapInsets:UIEdgeInsetsMake(44, 20, 44, 20)] forBarMetrics:UIBarMetricsDefault];        

Place this inside your viewDidLoad method. You'll need to link/import the QuartzCore framework.



来源:https://stackoverflow.com/questions/10823068/how-can-i-animate-the-uinavigationbar-background-change-on-uiviewcontroller-push

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