黏性tableView 下拉变长 毛玻璃效果渐变
2016-03-07 20:12
453 查看
// // MeController.m // E-flyer // // Created by Jason_Msbaby on 16/2/28. // Copyright © 2016年 Jason_Msbaby. All rights reserved. // #import "MeController.h" #import "SearchController.h" @interface MeController ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource> @property (weak, nonatomic) IBOutlet UITableView *tableView; @property (weak, nonatomic) IBOutlet UIImageView *Header; @property (weak, nonatomic) IBOutlet UIVisualEffectView *HeaderMask; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *HeaderH; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *HeaderMaskH; @property(assign,nonatomic) CGFloat basicH; @end @implementation MeController -(void)viewDidLoad{ [super viewDidLoad]; self.tableView.contentInset = UIEdgeInsetsMake(130, 0, 0, 0); _basicH = 150; } #pragma mark - ScrollViewDelegate /*! * 计算scrollView的滚动距离 改变顶部view的高度实现黏性headerView * * @param scrollView */ - (void)scrollViewDidScroll:(UIScrollView *)scrollView{ CGFloat h = -scrollView.contentOffset.y; //在拉伸的过程中偏移量总是保持在1->0.5之间 //所以变化不明显 //根据h的变化规律 从0开始依次逐大递增至0.5 //然后减掉这个变化的值就能够实现透明度在短距离的拉伸过程中从1->0的变化😄 CGFloat regulation = (h/_basicH-1)*0.5; CGFloat alpha = 150 / h - regulation; alpha -= regulation; NSLog(@"%f",alpha); if (h <= _basicH) { h = _basicH; } //更改毛玻璃透明度 self.HeaderMask.alpha = alpha; self.HeaderH.constant = h; self.HeaderMaskH.constant = h; } #pragma mark - tableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 40; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"meCell"]; // cell.backgroundColor = kRandomColor; return cell; } @end
相关文章推荐
- 51nod p1201 整数划分
- 免费试用阿里云空间和邮箱服务
- LeetCode : Merge Two Sorted Lists [java]
- 331. Verify Preorder Serialization of a Binary Tree
- C#面向对象
- [GDKOI2016]项链
- Spark Shuffle 堆外内存溢出问题与解决(Shuffle通信原理)
- 数据库事物四大特性-ACID
- BZOJ_P3561 DZY Loves Math VI(数论+莫比乌斯反演)
- zhuan:串口成帧协议
- 4198: [Noi2015]荷马史诗 贪心+优先队列
- py解析xml
- 树, 二叉树, 二叉搜索树
- Java基础面试点(1)
- 仿QQ滑动删除消息效果
- 密封
- JavaScript调用后台的三种方法实例
- opencv初探(二)
- python的一些有关定义的语法细节
- http://download.csdn.net/download/soft2buy/6515417