简体   繁体   English

淡出NavigationBar标题

[英]Fade out NavigationBar title

I have a scrollView with paging enabled. 我有一个启用分页的scrollView。 When i start to drag to the next page i want to text in my navigationBar smoothly fade out. 当我开始拖动到下一页时,我想在我的导航栏中文本顺利淡出。 I do it with delegate method: 我用委托方法做到了:

-(void)scrollViewDidScroll:(UIScrollView *)scrollView

I calculate the percent of dragging with: 我用以下公式计算拖动百分比:

CGFloat percentDragging = 1 - fmodf(scrollView.contentOffset.x,self.view.frame.size.width)/self.view.frame.size.width;

And this return right values. 这回归正确的价值观。

So: I try to set: 所以:我试着设置:

self.navigationController.navigationBar.titleView.alpha = percentDragging

but it didn't work. 但它不起作用。

I solved the problem by: 我解决了这个问题:

((UIView*)[[self.navigationController.navigationBar subviews] objectAtIndex:1]).alpha = percentDragging;

But this is ugly, crude, dangerous solution. 但这是一个丑陋,粗暴,危险的解决方案。 There is a better way? 有一个更好的方法?

Setting the titleView 's alpha didn't work because that doesn't give you access to the default navigation-bar title label—it only has a value when you've set one. 设置titleView的alpha不起作用,因为它不允许您访问默认的导航栏标题标签 - 它只有在您设置一个值时才有值。 I think what you'll have to do here is set a custom titleView yourself, containing a UILabel with font/shadow/etc. 我想你在这里要做的是自己设置一个自定义titleView,包含一个带字体/阴影/等的UILabel。 set to match the standard style, and fade that label in and out with your transition. 设置为匹配标准样式,并在转换时淡入或淡出该标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM