黏性tableView 下拉变长 毛玻璃效果渐变

//
//  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


转载于:https://my.oschina.net/zhangjie9142/blog/632354

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值