iOS navigationBar和tabBar变透明 & navigationBar根据滑动距离的渐变色实现
2016-08-30 15:52
771 查看
[b]navigationBar变为纯透明[/b]
//第一种方法
//导航栏纯透明
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
//去掉导航栏底部的黑线
self.navigationBar.shadowImage = [UIImage new];
//第二种方法
[[self.navigationBar subviews] objectAtIndex:0].alpha = 0;
[b]tabBar同理[/b]
[self.tabBar setBackgroundImage:[UIImage new]];
self.tabBar.shadowImage = [UIImage new];
[b]navigationBar根据滑动距离的渐变色实现[/b]
//第一种
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetToShow = 200.0;//滑动多少就完全显示
CGFloat alpha = 1 - (offsetToShow - scrollView.contentOffset.y) / offsetToShow;
[[self.navigationController.navigationBar subviews] objectAtIndex:0].alpha = alpha;
}
//第二种
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetToShow = 200.0;
CGFloat alpha = 1 - (offsetToShow - scrollView.contentOffset.y) / offsetToShow;
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
[self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[[UIColor orangeColor]colorWithAlphaComponent:alpha]] forBarMetrics:UIBarMetricsDefault];
}
//生成一张纯色的图片
- (UIImage *)imageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
//第一种方法
//导航栏纯透明
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
//去掉导航栏底部的黑线
self.navigationBar.shadowImage = [UIImage new];
//第二种方法
[[self.navigationBar subviews] objectAtIndex:0].alpha = 0;
[b]tabBar同理[/b]
[self.tabBar setBackgroundImage:[UIImage new]];
self.tabBar.shadowImage = [UIImage new];
[b]navigationBar根据滑动距离的渐变色实现[/b]
//第一种
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetToShow = 200.0;//滑动多少就完全显示
CGFloat alpha = 1 - (offsetToShow - scrollView.contentOffset.y) / offsetToShow;
[[self.navigationController.navigationBar subviews] objectAtIndex:0].alpha = alpha;
}
//第二种
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetToShow = 200.0;
CGFloat alpha = 1 - (offsetToShow - scrollView.contentOffset.y) / offsetToShow;
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
[self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[[UIColor orangeColor]colorWithAlphaComponent:alpha]] forBarMetrics:UIBarMetricsDefault];
}
//生成一张纯色的图片
- (UIImage *)imageWithColor:(UIColor *)color
{
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theImage;
}
相关文章推荐
- [iOS微博项目 - 1.4] - 各种item NavigationBar & NavigationItem & BarButtonItem || TabBar & TabBarItem
- Status bar and navigation bar appear over my view's bounds in iOS 7
- IOS 实现系统UINavigationController UINavigationBar 透明效果
- [iOS diary]iOS6样式兼容之 NavigationBar和TabBar 样式扁平化 兼容iOS7样式 全局实现
- IOS实现自定义透明背景的tabbar
- iphone ios navagationbar navigationItem 顶部如何实现下拉框 dropdownlist
- iOS - 实现映客首页 TabBar 和滑动隐藏 NavBar 和 TabBar
- iOS Swift&OC 模仿主流App 实现滑动视图隐藏导航栏
- 根据滑动显隐状态栏的iOS实现
- ios学习笔记----实现一个带滑动手势的tabBarViewController,并可自定义tabBar
- iOS 设置UINavtionController navigationBar 为透明颜色
- 详解 iOS navigationBar 的设置问题 详解2 关于隐藏和透明问题
- iOS实现UIImageView透明区域点击事件穿透(OC&swift)
- iOS Navigation Bar 导航栏折腾记 (Swift&OC)
- iosnavigationbar渐变的简单实现
- iOS Newbie - Xcode 7 & iOS 9 Navigation Bar & Status Bar
- iOS NavigationController NavigationBar设置透明
- iOS ----- navigationController.navigationBar 设置背景透明
- 设置navigation完全透明效果(How to make navigation bar transparent in iOS 7)
- BottomNavigationBar和VieaPage实现滑动切换