ios - 过渡导航栏标题

标签 ios objective-c animation uinavigationbar transition

在名为“Luvocracy”的应用中,当用户在屏幕上向上滑动时,导航栏的标题会发生变化。旧标题被推上去,而新标题被过渡进来。我现在没有它的视频,但这里有一些屏幕截图:

https://www.dropbox.com/s/sns0bsxkdv7pw3l/Photo%20Apr%2008%2C%2011%2001%2005%20AM.png

https://www.dropbox.com/s/ys9a49u3dyxrlcm/Photo%20Apr%2008%2C%2011%2001%2009%20AM.png

https://www.dropbox.com/s/dlcfvfvqqov3ag7/Photo%20Apr%2008%2C%2011%2001%2013%20AM.png

如何在显示的新导航栏标题中设置动画或过渡?

编辑:应用商店中不再提供该应用,因此我无法上传此操作的视频。

最佳答案

您可以使用 CATransition 为标题更改设置动画...但是,由于标题本身是导航栏上的私有(private)属性,因此您需要先创建自定义标签并将其附加到导航项。

设置标题标签(这将覆盖默认导航栏的标题):

UILabel *titleLabelView = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 44.0f) /* auto-sized anyway */];
titleLabelView.backgroundColor = [UIColor clearColor];
titleLabelView.textAlignment = NSTextAlignmentCenter;
titleLabelView.textColor = [UIColor blackColor];
titleLabelView.font = [UIFont systemFontOfSize:16.0f];
titleLabelView.adjustsFontSizeToFitWidth = YES;
titleLabelView.text = @"@cracy123";
self.navigationItem.titleView = titleLabelView;

然后每当你想为标题的变化设置动画时(假设在 ScrollView 委托(delegate)操作上),添加一个 CAAnimation 层和 presto:

CATransition *animation = [CATransition animation];
animation.duration = 1.0;
animation.type = kCATransitionPush;
animation.subtype = kCATransitionFromTop;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
[self.navigationItem.titleView.layer addAnimation:animation forKey:@"changeTitle"];

((UILabel*)self.navigationItem.titleView).text = @"JACOB K";

显然,您可以更改 CATransition 动画属性以获得您想要的效果,但这些会给您带来“俯卧撑”效果。

enter image description here

关于ios - 过渡导航栏标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22940940/

相关文章:

ios - 在 Swift 上存储表格数据

objective-c - 使用 NSString 显示百分比

python - 一个步骤的 Matplotlib 动画

jquery - 有什么办法可以从下面给出的动画功能中获取 top 的当前值

jquery - 如何在 Bootstrap 3 中制作进度条动画?

ios - 在 TableView 选项中获取行 ID

iphone - RestKit 映射嵌套字典中的值

iOS 9 Facebook 登录模拟器-canOpenURL : failed for URL: "fbauth2:///" - error: "(null)"

objective-c - 以只读方式返回一个对象

ios - 在 viewController 中重新加载一个 tableView