当前位置: 首页 > news >正文

UIScrollView视差模糊效果

UIScrollView视差模糊效果

 

效果

 

源码

https://github.com/YouXianMing/Animations


//
//  ScrollBlurImageViewController.m
//  Animations
//
//  Created by YouXianMing on 15/11/25.
//  Copyright © 2015年 YouXianMing. All rights reserved.
//

#import "ScrollBlurImageViewController.h"
#import "MoreInfoView.h"
#import "UIView+SetRect.h"
#import "Math.h"
#import "UIImage+ImageEffects.h"

static int viewTag = 0x11;

@interface ScrollBlurImageViewController () <UIScrollViewDelegate>

@property (nonatomic, strong) NSArray       *picturesArray;
@property (nonatomic, strong) UIScrollView  *scrollView;
@property (nonatomic, strong) Math          *onceLinearEquation;

@end

@implementation ScrollBlurImageViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];
}

- (void)setup {
    
    [super setup];
    
    MATHPoint pointA = MATHPointMake(0, -50);
    MATHPoint pointB = MATHPointMake(self.view.width, self.view.width - 50);;

    self.onceLinearEquation = [Math mathOnceLinearEquationWithPointA:pointA PointB:pointB];
    
    // Init pictures data.
    self.picturesArray = @[[UIImage imageNamed:@"beauty"],
                           [[UIImage imageNamed:@"beauty"] blurImage],
                           [[UIImage imageNamed:@"beauty"] grayScale]];
    
    // Init scrollView.
    CGFloat height = self.view.height;
    CGFloat width  = self.view.width;
    
    _scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
    _scrollView.delegate                       = self;
    _scrollView.pagingEnabled                  = YES;
    _scrollView.backgroundColor                = [UIColor blackColor];
    _scrollView.showsHorizontalScrollIndicator = NO;
    _scrollView.bounces                        = NO;
    _scrollView.contentSize                    = CGSizeMake(self.picturesArray.count * width, height);
    [self.view addSubview:_scrollView];
    
    // Init moreInfoViews.
    for (int i = 0; i < self.picturesArray.count; i++) {
        
        MoreInfoView *show     = [[MoreInfoView alloc] initWithFrame:CGRectMake(i * width, 0, width, height)];
        show.imageView.image   = self.picturesArray[i];
        show.layer.borderWidth = 0.25f;
        show.layer.borderColor = [[UIColor grayColor] colorWithAlphaComponent:0.25f].CGColor;
        show.tag               = viewTag + i;
        
        [_scrollView addSubview:show];
    }
    
    [self bringTitleViewToFront];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    CGFloat X = scrollView.contentOffset.x;
    
    for (int i = 0; i < self.picturesArray.count; i++) {
        
        MoreInfoView *show = [scrollView viewWithTag:viewTag + i];
        show.imageView.x   = _onceLinearEquation.k * (X - i * self.view.width) + _onceLinearEquation.b;
    }
}

@end

细节


相关文章:

  • 真正的上锁前,为何要调用preempt_disable()来关闭抢占的case【转】
  • 【烈日炎炎战后端】Linux(0.3万字)
  • POJ3159 Candies(最短路径:SPFA+链表+栈)
  • 【烈日炎炎战后端】SpringMVC(0.5万字)
  • 【shell 脚本】两种登录方式
  • 【烈日炎炎战后端】Spring(2.1万字)
  • tcpdump统计http请求
  • 产品经理技能之MRD的笔记之一
  • 【烈日炎炎战后端】消息队列(1.0万字)
  • css笔记:如何让一个div居于页面正中间
  • 【烈日炎炎战后端】Git(0.1万字)
  • R语言 如何为图片添加文字说明(转载)
  • 【烈日炎炎战后端 】MyBatis(0.4万字)
  • Windows Docker的有趣事实
  • RSD和wlwmanifest是什么
  • Angular4 模板式表单用法以及验证
  • Bootstrap JS插件Alert源码分析
  • express + mock 让前后台并行开发
  • Git 使用集
  • Java方法详解
  • Java精华积累:初学者都应该搞懂的问题
  • Laravel Telescope:优雅的应用调试工具
  • Linux Process Manage
  • nodejs实现webservice问题总结
  • supervisor 永不挂掉的进程 安装以及使用
  • underscore源码剖析之整体架构
  • vue-cli在webpack的配置文件探究
  • Windows Containers 大冒险: 容器网络
  • 构建工具 - 收藏集 - 掘金
  • 基于 Ueditor 的现代化编辑器 Neditor 1.5.4 发布
  • 记一次用 NodeJs 实现模拟登录的思路
  • 排序算法学习笔记
  • 如何使用 OAuth 2.0 将 LinkedIn 集成入 iOS 应用
  • 小程序测试方案初探
  • puppet连载22:define用法
  • 格斗健身潮牌24KiCK获近千万Pre-A轮融资,用户留存高达9个月 ...
  • 回归生活:清理微信公众号
  • 继 XDL 之后,阿里妈妈开源大规模分布式图表征学习框架 Euler ...
  • 你学不懂C语言,是因为不懂编写C程序的7个步骤 ...
  • 选择阿里云数据库HBase版十大理由
  • $.ajax()参数及用法
  • $.proxy和$.extend
  • $var=htmlencode(“‘);alert(‘2“); 的个人理解
  • (C++17) std算法之执行策略 execution
  • (二)WCF的Binding模型
  • (十八)用JAVA编写MP3解码器——迷你播放器
  • (十六)Flask之蓝图
  • (学习日记)2024.04.04:UCOSIII第三十二节:计数信号量实验
  • (转)Linq学习笔记
  • (转)socket Aio demo
  • .NET Core WebAPI中使用swagger版本控制,添加注释
  • .NET Framework与.NET Framework SDK有什么不同?
  • .net 获取url的方法
  • .Net 应用中使用dot trace进行性能诊断
  • .NET命令行(CLI)常用命令