xiaofei86 / XFBlogDemo

This repository is all my blog Demo.
http://xuyafei.cn
86 stars 22 forks source link

出现一个bug #1

Open q351941406 opened 8 years ago

q351941406 commented 8 years ago

如果有一个颜色设置[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:228.0f/255.0f green:42.0f/255.0f blue:76.0f/255.0f alpha:1]]; 我就必须把方案3里的所有.translucent = NO,才行,不然得不到我想要的色值,我导航栏就是不透明的,设置为NO之后才是我要的颜色,但为NO之后,方案三就到处是bug了,能解决得了吗?

xiaofei86 commented 8 years ago

[_bar setFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, 64)]; 改成 [_bar setFrame:CGRectMake(0, -64, UIScreen.mainScreen.bounds.size.width, 64)]; 因为translucent = NO后原点从NavBar下开始。所以添加的假的NavBar就跑到下边了。

q351941406 commented 8 years ago

我改了,但方案三里push后要隐藏的bar居然不隐藏了。。。。

q351941406 commented 8 years ago

方案二改为translucent = NO后也不隐藏了,我可以加你个QQ讨论下吗

q351941406 commented 8 years ago

还有bug,在translucent = NO 之后,push一个普通的VC,是可以设置bar的Y=0,但如果push的是tableVIewVC,就必须得设置bar的Y=-64,两种情况。

xiaofei86 commented 8 years ago

65803387 加我QQ说吧。

xiaofei86 commented 8 years ago

不要用translucent = NO了。换成 extendedLayoutIncludesOpaqueBars = YES。你照着源代码按照下边步骤改。

如果用方案3,你需要。 1.加载之前[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]]; 2.viewDidLoad方法里self.extendedLayoutIncludesOpaqueBars = YES; 3.addFakeNavBar方法里_bar.translucent = NO; 4.viewWillAppear方法里那行备注下边self.navigationController.navigationBar.translucent = YES; 5.viewDidAppear方法里那行备注下边self.navigationController.navigationBar.translucent = NO;

如果要用方案2。你只需要将假的UINavigation换成UIView。这在博客里有提到。

这个库只是博客里的Demo,主要讲的实现思路。你看看博客里写的理解下这些方案的原理就能根据自己的需求改了。

xiaofei86 commented 8 years ago

方案 3 隐藏 NavBar 是通过setBackgroundImage来实现。你设置了translucent 和 appearance 的 barTintColor,就不能通过 setBackgroundImage 隐藏背景了。这种方案的实现思路就是在执行动画的时候隐藏系统NavBar的背景,然后给相关 Controller 被标记不隐藏 NavBar 的添加假的 NavBar 充当背景。动画完成后删除假的 NavBar,再根据 appearance 的一些参数来恢复原来 NavBar。理解这些了你就可以自己改了。

方案 3 的思路相对复杂点,如果没有时间先理解的话,还是用方案 2 比较好。隐藏所有的 NavBar。给所有 Controller 添加假的 NavBar 或 UIView。简单粗暴。

UITableViewController 没有测试过。如果有问题应该可以提用过调整下边这才参数解决。 self.edgesForExtendedLayout = UIRectEdgeNone/UIRectEdgeAll; self.extendedLayoutIncludesOpaqueBars = YES/NO; self.automaticallyAdjustsScrollViewInsets = YES/NO; 要是解决不了你再提问。