方法一遍历法:

在你需要隐藏的地方调用如下代码

[self findlineviw:self.navigationBar].hidden = YES;

-(UIImageView*)findlineviw:(UIView*)view{

if ([view isKindOfClass:[UIImageView class]]&&view.bounds.size.height<=1.0) {

return (UIImageView*) view;

}for (UIImageView *subview in view.subviews) {

UIImageView *lineview = [self findlineviw:subview];

if (lineview) {

return lineview;

}

}

return nil;

}

方法二:注意这两句代码一句需要同时配合使用才有效果,可以在不同函数调用,但是必须保证两句代码都会执行到。

self.navigationBar.shadowImage = [UIImage new];

[self.navigationBar setBackgroundImage:[UIImage imageWithColor:kClearColor] forBarMetrics:UIBarMetricsDefault];

二,设置导航栏浙变

方法一:

定制一个view添加到导航栏上:

- (UIView *)navBarView {

if (!_navBarView) {

UIView *navBarView = [[UIView alloc] init];

navBarView.frame = CGRectMake(0, -20, kScreenWidth, 64);

[self.navigationController.navigationBar addSubview:navBarView];

self.navBarView = navBarView;

}

return _navBarView;

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

self.navigationItem.title = @"";

CGFloat offsetY = scrollView.contentOffset.y;

if (offsetY > startH) {

CGFloat alpha = MIN(1, 1 - ((startH + 64 - offsetY) / 64));

NSLog(@"%f",alpha);

self.navBarView.backgroundColor = [kBlackColor colorWithAlphaComponent:alpha];

if (offsetY >= (startH + 64)){

//这里设置滚动的时候是否显示标题,不需要可以注释掉

self.navigationItem.title = @"主页";

}

} else {

self.navBarView.backgroundColor = kClearColor;

}

}

方法二:直接改变导航栏的颜色

申明:

/** 滚动到多少高度开始出现 */

static CGFloat const startH = 0;

/** 导航条View */

@property (nonatomic, weak) UIView *navBarView;

实现:

-(void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

//设置导航栏的初始颜色

// [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[UIColor clearColor]] forBarMetrics:UIBarMetricsDefault];

//建议用这个方法设置初始化颜色,如果不设置barTintColor的颜色,那setBackgroundImage为clearColor时导航栏底色会成默认色

self.navigationController.navigationBar.barTintColor=[UIColor orangeColor];

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

//这里设置滚动的时候是否显示标题,不需要可以注释掉

self.navigationItem.title = @"";

CGFloat offsetY = scrollView.contentOffset.y;

if (offsetY > startH) {

CGFloat alpha = MIN(1, 1 - ((startH + 64 - offsetY) / 64));

NSLog(@"%f",alpha);

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[kBlackColor colorWithAlphaComponent:alpha]] forBarMetrics:UIBarMetricsDefault];

if (offsetY >= (startH + 64)){

//这里设置滚动的时候是否显示标题,不需要可以注释掉

self.navigationItem.title = @"主页";

}

} else {

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:kClearColor] forBarMetrics:UIBarMetricsDefault];

}

}

方法三:导航栏浙变

- (void)viewDidLoad {

[super viewDidLoad];

self.view.backgroundColor = [UIColor redColor];

self.navigationController.navigationBar.barTintColor = [UIColor blueColor];

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

CGFloat offset = scrollView.contentOffset.y;

if (offset<=0&&offset<=-90) {

self.navigationController.navigationBar.alpha = 0;

}else if(offset<=500){

self.navigationController.navigationBar.alpha = offset/200;

}

}

类扩展的方法:

+ (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 *image = UIGraphicsGetImageFromCurrentImageContext();

UIGraphicsEndImageContext();

return image;

}

三、滚动时改变状态栏的颜色:

-(void)viewWillAppear:(BOOL)animated
{ self.navigationController.navigationBarHidden = YES;
UIView *statusBarView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
statusBarView.backgroundColor = kOrangeColor;
[self.view addSubview:statusBarView];
_statusBarView = statusBarView;
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

CGFloat offsetY = scrollView.contentOffset.y;
if (offsetY > startH) {
CGFloat alpha = MIN(1, (1 - ((startH + 64 - offsetY) / 64))/10.f);
NSLog(@"%f",alpha);
_statusBarView.backgroundColor = [kBlackColor colorWithAlphaComponent:alpha];
// [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:[kBlackColor colorWithAlphaComponent:alpha]] forBarMetrics:UIBarMetricsDefault];
if (offsetY >= (startH + 64)){
_homePageTableView.backgroundColor = kColorHexValue(0xe6ebeb, 1);
}
} else {
_homePageTableView.backgroundColor = kOrangeColor;
_statusBarView.backgroundColor = kOrangeColor;

// [self.navigationController.navigationBar setBackgroundImage:[UIImage imageWithColor:kClearColor] forBarMetrics:UIBarMetricsDefault];
}
}

ios隐藏导航栏底线条和导航、状态栏浙变色的更多相关文章

  1. IOS 实现自定义的导航栏背景以及自定义颜色的状态栏(支持7.0以及低版本)

    为尊重文章原作者,转载务必注明原文地址:http://www.cnblogs.com/wt616/p/3784717.html 先看效果图: 在自定义导航栏背景时,可能会遇到以下一些问题: 1.当设置 ...

  2. Jquery实现动态导航栏和轮播导航栏

    动态导航栏和轮播导航栏的实现思想: 利用jquery技术的append()方法和bind()方法实现li标签的添加和点击事件绑定,在利用$getJSON(url,data,function)请求方法实 ...

  3. 微信小程序入门四: 导航栏样式、tabBar导航栏

    实例内容 导航栏样式设置 tabBar导航栏 实例一:导航栏样式设置 小程序的导航栏样式在app.json中定义. 这里设置导航,背景黑色,文字白色,文字内容测试小程序 app.json内容: { & ...

  4. iOS WKWebView 加载进度条、导航栏返回&关闭 (Swift 4)

    导航: 1.加载进度条 2.导航栏增加返回.关闭按钮 加载进度条 效果图 代码如下: self.progressView.trackTintColor = UIColor.white self.pro ...

  5. iOS 导航栏 工具条

    导航栏最常见的例子就是返回按钮的所在 在AppDelegate.m中,代码布局最开始定义窗口的时候, _window.rootViewController就应该为一个UINavigationContr ...

  6. iOS侧滑返回到隐藏导航栏的VC,导航栏会闪现一次

    VCA:是一个隐藏导航栏的页面:VCA在ViewWillAppear生命周期函数中设置导航栏隐藏: //隐藏导航栏 [self.navigationController setNavigationBa ...

  7. Android仅2步实现 滚粗 汉堡导航栏效果~ 全新底部导航交互(滑动隐藏)

    本文同步自wing的地方酒馆 布吉岛大家有木有看这一篇文章,再见,汉堡菜单,我们有了新的 Android 交互设计方案 本库下载地址:https://github.com/githubwing/Bye ...

  8. iOS---实现简书和知乎的上滑隐藏导航栏下拉显示导航栏效果

    因为自己用简书和知乎比较多,所以对其导航栏的效果比较好奇,自己私下里找资料实现了一下.这个效果的关键点在于下方可供滑动的内容的便宜距离inset的改变,以及滑动的scrollview代理的执行,废话不 ...

  9. iOS 设置导航栏的颜色和导航栏上文字的颜色

    #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pr ...

随机推荐

  1. mac 卸载 XCode

    http://blog.csdn.net/songques/article/details/7244144

  2. 利用 jQuery-photoClip插件 实现移动端裁剪功能并以Blob对象上传

    最近客户要求实现论坛贴子附件裁剪功能,没有考虑js与ios.android容器交互解决方案,单纯用js去实现它的.由于本来附件上传用的别的插件实现的,所以是在此基础上费了不少劲,才把jQuery-ph ...

  3. cloudstack安装篇3-SELinux配置、NTP时间同步、配置ClouStack软件库

    一.SELinux配置 为了让CloudStack正常工作,我们必须将SELinux设置为permissive.需要在当前系统运行状态下和启动后都能够生效,进行以下配置. 在系统运行状态下的将SELi ...

  4. HW4.2

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  5. CF_402B 想法题

    题目链接:http://codeforces.com/problemset/problem/402/B /**算法分析: 题意太大意,positive没注意这个问题 考察等差数列,由An=A1+(n- ...

  6. CSS的一些规范

    请使用简单的语法来链接样式表(type 属性不是必需的): <link rel="stylesheet" href="styles.css"> 短规 ...

  7. RH442之Tuned优化方案

    系统优化 介绍: Tuned是监控并收集系统组件使用资源的守护进程,可根据收集信息动态调整系统,可调整CPU和网络资源的使用来提高活跃设备性能与不活跃设备电能消耗.通过tuned-adm中提供优化案例 ...

  8. IOS-Archiver文件归档(2)

    Archiver是持久化数据的一种方式,他跟 Plist的差别在于他能持久化自己定义对象.但他没Plist那么方便. Archiver默认能持久化的数据有NSNumber,NSArray,NSDict ...

  9. c++制作小游戏--雷电

    用c++实现了一个小游戏--雷电,貌似执行的还不错.贴图和声效也是Duang!Duang!的.整个项目我也会给出下载链接,有兴趣的能够编译执行一下.用到了C++11的新特性,最好是使用vs2013编译 ...

  10. 进程控制之wait3和wait4函数

    大多数UNIX系统实现提供了另外两个函数wait3和wait4.它们提供的功能比POSIX.1函数wait.waitpid和waitid所提供的功能要多一个,这与附加参数rusage有关.该参数要求内 ...