gpt4 book ai didi

ios - 如何为 UINavigationBar setBackgroundImage 设置动画 : forBarMetrics:?

转载 作者:技术小花猫 更新时间:2023-10-29 11:10:31 25 4
gpt4 key购买 nike

当按下某个 Controller 时,我正在更改导航栏的背景图像。我想为这种变化制作动画。我可以使用以下代码这样做:

[UIView transitionWithView:self.navigationController.navigationBar
duration:0.3f
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"now-playing-nav-bar.png"]
forBarMetrics:UIBarMetricsDefault];
} completion:NULL];

但是,这会阻止应用于 navigationBarTitleUIBarButtonItem 的默认推送动画。

如何让背景变化和推送动画协同工作?

我更喜欢尽可能普通的解决方案。

PS:我不能使用tintColor,因为背景有纹理。

最佳答案

仅在 iOS 6 上测试

我使用 Core Animation 解决了它:

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];

CATransition *animation = [CATransition animation];
animation.duration = 0.3;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.type = kCATransitionFade;

[self.navigationController.navigationBar.layer addAnimation:animation forKey:nil];

[UIView animateWithDuration:0.3 animations:^{
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"now-playing-nav-bar.png"] forBarMetrics:UIBarMetricsDefault];
}];
}

viewWillDisappear: 中做同样的事情,你就可以开始了。

关于ios - 如何为 UINavigationBar setBackgroundImage 设置动画 : forBarMetrics:?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14602759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com