iOS滑动tableView来改变导航栏的颜色
2016-02-29 09:43
363 查看
- (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 获取照相机实时预览图片
- iOS自定义转场动画实战讲解
- iOS 开发之动画篇 - Transform和KeyFrame动画
- iOS-私有API与runtime
- iOS开发——iOS状态栏和导航栏的控制问题
- IOS设计模式之组合设计模式
- iOS开发:WebKit、Safari以及SafariViewController
- Nagios+NRPE安装备忘录(一)
- iOS检查继承关系
- 总结iOS App开发中控制屏幕旋转的几种方式
- iOS崩溃调试
- 整理常用的iOS第三方资源
- iOS 关闭键盘 [self endEditing: YES]
- 让web应用正常显示ios输入法表情
- 如何让自己的web应用支持iOS表情
- [ios]iOS 图形编程总结
- iOS中Quartz2D图片裁剪和图片增加文字描述
- iOS MVC设计模式与MVVM设计模式简介 —— HERO博客
- [iOS] 绘图 CGContext 用法
- ios 照相机和相册的调用