在一个名为“Luvocracy”的应用程序中,当用户在屏幕上向上滑动时,导航栏的标题会发生变化。旧标题被推高,而新标题则过渡进来。我现在没有视频,但这里有一些屏幕截图:
https://www.dropbox.com/s/sns0bsxkdv7pw3l/Photo%20Apr%2008%2C%2011%2001%2005%20AM.png 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/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 https://www.dropbox.com/s/dlcfvfvqqov3ag7/Photo%20Apr%2008%2C%2011%2001%2013%20AM.png
如何在新的导航栏标题中设置动画或过渡,如图所示?
编辑:该应用程序在应用程序商店中不再可用,因此我无法上传此操作的视频。
您可以使用 CATransition 对标题更改进行动画处理...但是,由于标题本身是导航栏上的私有属性,因此您需要首先创建一个自定义标签并将其附加到导航项。
设置标题标签(这将覆盖默认导航栏的标题):
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;
然后,每当您想要为标题更改设置动画时(假设滚动视图委托操作),请添加一个 CAAnimation 层并立即执行:
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 动画属性来获得您想要的效果,但这些会给您带来“俯卧撑”效果。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)