iOS滑动tableView来改变导航栏的颜色
2016-07-14 16:41
477 查看
(void)viewDidLoad {
[super viewDidLoad];
[self initTableView];
}
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 10;
}
(UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[self tableViewZ:self.myTableView cellForRowAtIndexPath:indexPath];
return cell;
}
(UITableViewCell )tableViewZ:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[[UITableViewCell alloc]init];
return cell;
}
(void)scrollViewDidScroll:(UIScrollView *)scrollView{
NSLog(@”offset—scroll:%f”,self.myTableView.contentOffset.y);
UIColor *color=[UIColor redColor];
CGFloat offset=scrollView.contentOffset.y;
if (offset<0) {
self.navigationController.navigationBar.backgroundColor = [color colorWithAlphaComponent:0];
}else {
CGFloat alpha=1-((64-offset)/64);
self.navigationController.navigationBar.backgroundColor=[color colorWithAlphaComponent:alpha];
}
}
(void)initTableView{
self.myTableView.delegate=self;
self.myTableView.dataSource=self;
}
[super viewDidLoad];
[self initTableView];
}
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 10;
}
(UITableViewCell )tableView:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[self tableViewZ:self.myTableView cellForRowAtIndexPath:indexPath];
return cell;
}
(UITableViewCell )tableViewZ:(UITableView )tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[[UITableViewCell alloc]init];
return cell;
}
(void)scrollViewDidScroll:(UIScrollView *)scrollView{
NSLog(@”offset—scroll:%f”,self.myTableView.contentOffset.y);
UIColor *color=[UIColor redColor];
CGFloat offset=scrollView.contentOffset.y;
if (offset<0) {
self.navigationController.navigationBar.backgroundColor = [color colorWithAlphaComponent:0];
}else {
CGFloat alpha=1-((64-offset)/64);
self.navigationController.navigationBar.backgroundColor=[color colorWithAlphaComponent:alpha];
}
}
(void)initTableView{
self.myTableView.delegate=self;
self.myTableView.dataSource=self;
}
相关文章推荐
- IOS 微软云 Azure 推送通知
- iOS 开发之照片框架详解
- 获取iOS 设备型号
- IOS开发-cocoaPod安装遇到的错误以及解决方法
- iOS之深入了解控制器View的加载
- ios键盘收起的常见方法
- iOS软件逆向思维
- iOS开发200个tips总结(一)
- iOS开发之JSPatch动态替换OC代码
- 《Motion Design for iOS》(三十五)
- iOS NSCoding 的学习 和 使用
- IOS 隐藏 导航栏 下面的黑线
- iOS音频编程之实时语音通信
- iOS开发之ijkplayer视频直播
- 为你的Xcode项目手动创建PCH文件
- iOS runtime解析(1)
- iOS开发Navigation 导航栏渐变
- iOS开发之Pop框架(三)
- IOS开发之制作静态库
- iOS开发之Pop框架(二)