好的,这不是一个完美的解决方案,但可能会给你一个起点:
导航栏标题之间的淡入淡出相当简单:
CATransition *fade = [CATransition animation];
fade.type = kCATransitionFade;
fade.duration = 2.0;
[self.navigationController.navigationBar.layer addAnimation: fade forKey: @"fadeText"];
self.navigationItem.title = "new Title";
您可以使用其他类型的“开箱即用”过渡来为标题的位置设置动画,例如:
CATransition *push = [CATransition animation];
push.duration = 2.0;
push.type = kCATransitionPush;
push.subtype = kCATransitionFromRight;
[self.navigationController.navigationBar.layer addAnimation: push forKey: @"pushText"];
self.navigationItem.title = "new Title";
这样做的问题是整个导航栏都会移动。为了解决这个问题,您需要在导航栏的子视图中找到标题标签的图层。此视图层次结构是“私有的”,因此您不应该将此代码提交到商店,但就像我说的……这可能会给您一个起点。
CATransition *fade = [CATransition animation];
fade.type = kCATransitionFade;
fade.duration = 2.0;
CATransition *move = [CATransition animation];
move.duration = 2.0;
move.type = kCATransitionMoveIn;
move.subtype = kCATransitionFromRight;
UILabel * navBarTitleLabel;
for (UIView * view in self.navigationController.navigationBar.subviews) {
if ([NSStringFromClass(view.class) isEqualToString: @"UINavigationItemView"]) {
navBarTitleLabel = view.subviews.firstObject;
break;
}
}
[navBarTitleLabel.layer addAnimation: fade forKey: @"fadeText"];
[navBarTitleLabel.layer addAnimation: move forKey: @"moveText"];
self.navigationItem.title = newTitle;
removeAllAnimations
一旦完成,您可能会发现需要从图层中删除。我没有机会完全测试它。