上划渐变导航条颜色
1.功能需求
剛進(jìn)入頁面導(dǎo)航條背景為透明色,上劃一定距離改變導(dǎo)航條顏色為白色(漸變)
2.功能實(shí)現(xiàn)
2.1 在viewWillAppera中實(shí)現(xiàn)導(dǎo)航條背景色透明
-(void)viewWillAppear:(BOOL)animated{[super viewWillAppear:animated];// 讓控件從(0,0)開始self.navigationController.navigationBar.translucent = YES;self.navigationController.navigationBar.shadowImage = [UIImage new];[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:0]; }2.2 在scrollView代理方法 scrollViewDidScroll中實(shí)現(xiàn)隨著滾動(dòng)改變導(dǎo)航欄顏色透明度//只要滾動(dòng)了就會(huì)觸發(fā) - (void)scrollViewDidScroll:(UIScrollView *)scrollView;{// 動(dòng)態(tài)更新navigationBar的顏色CGFloat offsetY = scrollView.contentOffset.y;if (offsetY > NAVBAR_CHANGE_POINT) {CGFloat alpha = MIN(1, 1 - ((NAVBAR_CHANGE_POINT + NavigationHeight - offsetY) / NavigationHeight));[self.navigationController.navigationBar setBackgroundImage:[FFCommonView createImageWithColor:[Color_NavigationBar colorWithAlphaComponent:alpha]] forBarMetrics:UIBarMetricsDefault];if (alpha == 1) {self.navigationController.navigationBar.translucent = NO;}else{self.navigationController.navigationBar.translucent = YES;}} else {[self.navigationController.navigationBar setBackgroundImage:[FFCommonView createImageWithColor:[Color_NavigationBar colorWithAlphaComponent:0]] forBarMetrics:UIBarMetricsDefault];} }
????ps:
????Navbar_change_point為導(dǎo)航條開始漸變色的距離;透明度變?yōu)?的時(shí)候設(shè)置translucent屬性為NO
?2.3 在viewWillDeillDisappear中還原之間的一些設(shè)置
-(void)viewWillDisappear:(BOOL)animated{[super viewWillDisappear:animated];self.navigationController.navigationBar.translucent = NO;//界面離開的時(shí)候重新設(shè)置回原來的樣式[self.navigationController.navigationBar setBackgroundImage:[FFCommonView createImageWithColor:Color_NavigationBar] forBarMetrics:UIBarMetricsDefault]; }總結(jié)
- 上一篇: dvi线支持多少分辨率_dvi接口有哪几
- 下一篇: NOIP 2008 普及组初赛试题 解题