毛玻璃效果随着tableView滑动清晰
来源:互联网 发布:半生缘 葛优 知乎 编辑:程序博客网 时间:2024/05/22 06:06
毛玻璃效果处理:
我们的需求是毛玻璃效果(高斯模糊)随着tableView向下滑动变的清晰,主要问题是页面渲染太多,在处理毛玻璃效果的时候页面非常卡顿,(iphone6以下)
查了很多资料页没有什么效果,后来在android大神的指导下完成需求,说一下原理吧:
做两张图片 一个是高斯模糊的 一个是清晰的 模糊的图片盖在清晰的上面 滑动tableView,改变模糊啊的那个透明度alpha,滑倒下面模糊的那个透明度就是0了,然后清晰的那个显示了, tableView滑动改变alpha不卡,效果也达到了。
由于公司项目保密,自己写了一个demo,欢迎读阅:
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)UIImageView *imageView1;
@property (nonatomic,strong)UIImageView *imageView2;
@property (nonatomic,strong)UIImage *image1;
@property (nonatomic,strong)UIImage *image2;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[selfcreatUI];
}
- (void)creatUI
{
self.imageView1 = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,375,667)];
self.image1 = [UIImageimageNamed:@"屏幕快照 2016-04-23上午10.36.46"];
self.imageView1.image =self.image1;
[self.viewaddSubview:self.imageView1];
self.imageView1.image = [self.image1gaussBlur:0];
self.imageView2 = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,375,667)];
self.image2 = [UIImageimageNamed:@"屏幕快照 2016-04-23上午10.36.46"];
self.imageView2.image =self.image2;
[self.viewaddSubview:self.imageView2];
self.imageView2.image = [self.image2gaussBlur:1];
self.tableView = [[UITableViewalloc]initWithFrame:CGRectMake(0,0,375,667)style:UITableViewStylePlain];
self.tableView.delegate =self;
self.tableView.dataSource =self;
self.tableView.backgroundColor = [UIColor clearColor];
[self.viewaddSubview:self.tableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil)
{
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"cell"];
}
cell.backgroundColor = [UIColorclearColor];
return cell;
}
#pragma mark - 模糊效果设置/分业显示
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offset=scrollView.contentOffset.y;
if (offset<0)
{
CGFloat alpha=((128+offset)/128);
self.imageView2.alpha = alpha;
// self.visualEffectView.alpha = alpha ;
NSLog(@"%lf",alpha);
}
else
{
self.imageView2.alpha =1;
}
}
下面这句话是对image的一个分类,处理高斯模糊的
self.imageView1.image = [self.image1 gaussBlur:0];
如还有不明白的请看代码
http://download.csdn.net/detail/qq_20176153/9502400
- 毛玻璃效果随着tableView滑动清晰
- navigationBar随着tableview滑动透明度渐变
- iOS tableview 区头随着cell滑动
- tableview的 子View 不随着tableview滑动
- 如何让UITableview的sectionHeader随着tableview一起滑动
- Cell特效之图片随着TableView的滑动上下移动
- 毛玻璃效果
- 毛玻璃效果
- 毛玻璃效果
- 毛玻璃效果
- 毛玻璃效果
- 毛玻璃效果
- 毛玻璃效果
- 毛玻璃效果
- 毛玻璃效果
- 毛玻璃效果
- 毛玻璃效果
- 毛玻璃效果
- #leetcode#202. Happy Number
- 内部类
- 51nod1049最大子段和
- 用android LinearLayout和RelativeLayout实现精确布局
- Android-ContextMenu上下文菜单
- 毛玻璃效果随着tableView滑动清晰
- 5-2 Verilog Moore状态机之带有游行模式的十字路口
- yii2基础(一)
- ZeroMQ的内部架构
- 分布式架构高可用架构篇_08_MyCat在MySQL主从复制基础上实现读写分离
- C经典 求二维数组的最大值与行,还有列
- Implement strStr()
- POJ-3468A Simple Problem with Integers,线段数区间更新查询,代码打了无数次还是会出错~~
- C#OOP之四 深入理解方法