本篇文章主要介绍了"黏性tableView 下拉变长 毛玻璃效果渐变",主要涉及到方面的内容,对于移动开发感兴趣的同学可以参考一下:
//
// MeController.m
// E-flyer
//
// Created by Jason_Msbaby on 16/2/28.
// ...
//
// 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 ()
@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
以上就介绍了黏性tableView 下拉变长 毛玻璃效果渐变,包括了方面的内容,希望对移动开发有兴趣的朋友有所帮助。
本文网址链接:http://www.codes51.com/article/detail_387592.html