gpt4 book ai didi

iphone - 过渡 UINavigationBar 颜色?

转载 作者:行者123 更新时间:2023-12-03 19:04:55 26 4
gpt4 key购买 nike

我基本上是在尝试在 iPhone 上复制 iPod 应用程序的行为,当您选择一首歌曲时,音乐播放器 View 会滑入,并且导航栏会转换为新的颜色。

我的应用程序设置为基于选项卡的应用程序,每个选项卡中都有 UITabBarController 和嵌套的 UINavigationController。每个选项卡的每个 UINavigationController 内部都有一个 UITableView。当我在表中选择一个项目时,我使用 pushViewController 滑动到下一个 View ,并且我在下一个 View Controller 中设置了 hidesBottomBarWhenPushed 以便滑动标签消失。该行为与 iPod“正在播放”页面非常接近,几乎完美。

最后一个问题是我无法转换导航栏的颜色,就像 iPod 应用程序中的导航栏从蓝色淡入黑色一样。我能够在新 View 出现后强制更改颜色(在 viewWillAppear 中),但更改是突然的,并且不会模仿 iPod 应用程序的行为,并具有淡入淡出效果。

有人知道我在这里缺少什么吗?这似乎是一个非常简单且常见的 UI,我在多个应用程序中都见过,但似乎没有明显的方法来做到这一点。

最佳答案

安德鲁的答案实际上效果很好,但我会添加两件事以使其更好:

  1. 通过类别而不是子类化提供功能。非常非常不那么困惑。
  2. 仅在绝对必要时才使用转换。其原因是,当使用此技术时,原始标题文本只会消失,而不是从侧面滑落。这是微妙的,但如果它发生在酒吧风格实际上没有改变的过渡期间,就会更加明显。所以我会避免这种情况。

这是我的类别代码(我在 UINavigationBar 和 UIToolbar 的类别中都有它):

- (void)setBarStyle:(UIBarStyle)barStyle animated:(BOOL)animated {
if (animated && self.barStyle != barStyle) {
CATransition *transition = [CATransition animation];
transition.duration = 0.2;
transition.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseIn];
[self.layer addAnimation:transition forKey:nil];
}

[self setBarStyle:barStyle];
}

这就是我使用它的方式:

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

[[UIApplication sharedApplication]
setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES];
[self.navigationController.navigationBar
setBarStyle:UIBarStyleBlackTranslucent animated:YES];
[self.navigationController.toolbar
setBarStyle:UIBarStyleBlackTranslucent animated:YES];
}

关于iphone - 过渡 UINavigationBar 颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/645232/

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