LineAnimationView

效果

说明

水平循环无间隔播放动画效果,用于loading的界面

源码

https://github.com/YouXianMing/UI-Component-Collection

//
// LineAnimationView.h
// AnimationLine
//
// Created by YouXianMing on 15/7/4.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h> typedef enum : NSUInteger { /**
* 从左往右(默认)
*/
LEFT_TO_RIGHT, /**
* 从右往左
*/
RIGHT_TO_LEFT, } ELineAnimationType; @interface LineAnimationView : UIView /**
* 动画时间间隔(默认时间为 1 秒)
*/
@property (nonatomic) NSTimeInterval duration; /**
* 动画类型(默认为从左到右)
*/
@property (nonatomic) ELineAnimationType animationType; /**
* 素材图片
*/
@property (nonatomic, strong) UIImage *sourceImage; /**
* 开始执行动画
*/
- (void)startAnimation; @end
//
// LineAnimationView.m
// AnimationLine
//
// Created by YouXianMing on 15/7/4.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import "LineAnimationView.h" @interface LineAnimationView () @property (nonatomic, strong) UIView *contentView; @property (nonatomic, strong) UIImageView *leftImageView;
@property (nonatomic, strong) UIImageView *rightImageView; @end @implementation LineAnimationView #pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame];
if (self) { [self defaultConfig]; [self setup];
} return self;
} - (void)defaultConfig { self.layer.masksToBounds = YES;
} - (void)setup { CGFloat width = self.frame.size.width;
CGFloat height = self.frame.size.height; self.contentView = [[UIView alloc] initWithFrame:CGRectMake(, , width * , height)];
[self addSubview:self.contentView]; self.leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(, , width, height)];
[self.contentView addSubview:self.leftImageView]; self.rightImageView = [[UIImageView alloc] initWithFrame:CGRectMake(width, , width, height)];
[self.contentView addSubview:self.rightImageView]; _animationType = LEFT_TO_RIGHT;
_duration = .f;
} #pragma mark - 开始动画
- (void)startAnimation { if (_animationType == LEFT_TO_RIGHT) { CGFloat width = self.frame.size.width;
CGFloat height = self.frame.size.height; CGRect startRect = CGRectMake(, , width * , height);
CGRect endRect = CGRectMake(-width, , width * , height); _contentView.frame = startRect; CABasicAnimation *line = [CABasicAnimation animationWithKeyPath:@"bounds"];
line.fromValue = [NSValue valueWithCGRect:startRect];
line.toValue = [NSValue valueWithCGRect:endRect];
line.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
line.duration = _duration;
line.delegate = self; _contentView.frame = endRect;
[_contentView.layer addAnimation:line forKey:nil]; } else if (_animationType == RIGHT_TO_LEFT) { CGFloat width = self.frame.size.width;
CGFloat height = self.frame.size.height; CGRect startRect = CGRectMake(- width, , width * , height);
CGRect endRect = CGRectMake(, , width * , height); _contentView.frame = startRect; CABasicAnimation *line = [CABasicAnimation animationWithKeyPath:@"bounds"];
line.fromValue = [NSValue valueWithCGRect:startRect];
line.toValue = [NSValue valueWithCGRect:endRect];
line.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
line.duration = _duration;
line.delegate = self; _contentView.frame = startRect;
[_contentView.layer addAnimation:line forKey:nil]; }
} - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { [self startAnimation];
} #pragma mark - 重写setter,getter方法
@synthesize sourceImage = _sourceImage;
- (void)setSourceImage:(UIImage *)sourceImage { _sourceImage = sourceImage;
_leftImageView.image = sourceImage;
_rightImageView.image = sourceImage;
} - (UIImage *)sourceImage { return _sourceImage;
} @end

细节

[控件] LineAnimationView的更多相关文章

  1. JS调用Android、Ios原生控件

    在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...

  2. HTML5 progress和meter控件

    在HTML5中,新增了progress和meter控件.progress控件为进度条控件,可表示任务的进度,如Windows系统中软件的安装.文件的复制等场景的进度.meter控件为计量条控件,表示某 ...

  3. 百度 flash html5自切换 多文件异步上传控件webuploader基本用法

    双核浏览器下在chrome内核中使用uploadify总有302问题,也不知道如何修复,之所以喜欢360浏览器是因为帮客户控制渲染内核: 若页面需默认用极速核,增加标签:<meta name=& ...

  4. JS与APP原生控件交互

    "热更新"."热部署"相信对于混合式开发的童鞋一定不陌生,那么APP怎么避免每次升级都要在APP应用商店发布呢?这里就用到了混合式开发的概念,对于电商网站尤其显 ...

  5. UWP开发必备:常用数据列表控件汇总比较

    今天是想通过实例将UWP开发常用的数据列表做汇总比较,作为以后项目开发参考.UWP开发必备知识点总结请参照[UWP开发必备以及常用知识点总结]. 本次主要讨论以下控件: GridView:用于显示数据 ...

  6. 【踩坑速记】开源日历控件,顺便全面解析开源库打包发布到Bintray/Jcenter全过程(新),让开源更简单~

    一.写在前面 自使用android studio开始,就被它独特的依赖方式:compile 'com.android.support:appcompat-v7:25.0.1'所深深吸引,自从有了它,麻 ...

  7. 对百度WebUploader开源上传控件的二次封装,精简前端代码(两句代码搞定上传)

    前言 首先声明一下,我这个是对WebUploader开源上传控件的二次封装,底层还是WebUploader实现的,只是为了更简洁的使用他而已. 下面先介绍一下WebUploader 简介: WebUp ...

  8. Windows API 设置窗口下控件Enable属性

    参考页面: http://www.yuanjiaocheng.net/webapi/create-crud-api-1-put.html http://www.yuanjiaocheng.net/we ...

  9. VB.NET设置控件和窗体的显示级别

    前言:在用VB.NET开发射频检测系统ADS时,当激活已存在的目标MDI子窗体时,被其他子窗体遮住了,导致目标MDI子窗体不能显示. 这个问题怎么解决呢?网上看到一篇帖子VB.NET设置控件和窗体的显 ...

随机推荐

  1. 用sinopia搭建内部npm服务

    sinopia搭建 这里默认你已经有node环境了,执行下面命令,全局安装 sinopia npm install -g sinopia 安装好后,执行下面命令启动 sinopia sinopia 你 ...

  2. Redis的服务命令(实现开机自启动)

    在Redis的安装目录下,有一个redis.windows-service.conf文件,即默认的配置文件, 如果需要修改端口号,或者设置密码就需要修改其中的内容: 默认端口号是6379,你可以随意修 ...

  3. apache的rewrite规则来实现URL末尾是否带斜杠

    1.url: http://www.test.com/user/ 跟:http://www.test.com/user 这两个URL对于用户来说应该是一样的,但从编程的角度来说,它们可以不相同 但我们 ...

  4. C#(Winform)中button的Enable=false和visible的区别

    Enable:可用性 visible:可见性(不是visiable哦,没有这个单词) 如果设置了button或其他控件的Enable为false,还是能够看到控件,只是控件是灰色的,而且点不了: 但设 ...

  5. 获得Spring容器

    1. WebApplicationContext wac = ContextLoader.getCurrentWebApplicationCon; 2. ClassPathXmlApplication ...

  6. nginx 学习笔记(3) nginx管理

    nginx可以通过向其发送信号来进行管理.默认情况下主进程的进程ID写到文件/usr/local/nginx/logs/nginx.pid中.当然也可以在配置文件中自定义该pid文件,自定义使用pid ...

  7. eclipse 中文件引用报错不能编译,但引用文件确实存在

    方法1:clean工程 方法2: 检查.classpath文件中该引用文件是否被排除在外.

  8. window.history的跳转实质-HTML5 history API 解析

    在上一浏览器跳转行为的测试中,我们看到了通过不同的方法操作浏览器跳转时,它的刷新表现有所不同,在这一文章中,将看看,为何会产生这样的不同?其背后的实质是什么?浏览器的访问历史记录到底是如何运作的呢? ...

  9. HTTP协议以及HTTP请求中8种请求方法

    HTTP协议以及HTTP请求中8种请求方法 什么是协议? 协议,是指通信的双方,在通信流程或内容格式上,共同遵守的标准. 什么是http协议? http协议,是互联网中最常见的网络通信标准. http ...

  10. [CTSC 2018]假面

    Description 题库链接 有 \(n\) 个敌方单位,初始第 \(i\) 个单位的血量为 \(m_i\) .共 \(Q\) 次操作,分两种: 对某一个单位以 \(p\) 的概率造成 \(1\) ...