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. Java虚拟机(五):JVM调优命令

    运用jvm自带的命令可以方便的在生产监控和打印堆栈的日志信息帮忙我们来定位问题!虽然jvm调优成熟的工具已经有很多:jconsole.大名鼎鼎的VisualVM,IBM的Memory Analyzer ...

  2. elasticsearch插件安装之--拼音插件

    /** * vm12下的centos7.2 * elasticsearch 5.2.2 */ 有时在淘宝搜索商品的时候, 会发现使用汉字, 拼音, 或者拼音混合汉字都会出来想要的搜索结果, 今天找了一 ...

  3. Beta阶段——Scrum 冲刺博客第三天

    一.当天站立式会议照片一张 二.每个人的工作 (有work item 的ID),并将其记录在码云项目管理中 昨天已完成的工作 实现部分question页面的制作,制作内容包括题目序号的制作,同时在最后 ...

  4. 从数据库表中随机获取N条记录的SQL语句

    Oracle: select * from (select * from tableName order by dbms_random.value) where rownum < N MS SQ ...

  5. sql基础语法大全 转载过来的,出处忘了!

    一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...

  6. C语言读取配置文件

    自从大学学完C之后,就再也没用过它了, 在网上找代码,七拼八凑之后,终于成形~~勉强能用,不喜勿喷,^_^! int GetValue(const wchar_t *key, wchar_t *val ...

  7. npm saveError ENOENT: no such file or directory

    1.报错情况 在执行npm install xxx时,出现如下:npm WARN saveError ENOENT: no such file or directory, open '/nodetes ...

  8. shell与expect结合使用

    在linux操作系统下,使用脚本自动化,一般由两种方案,方案一:telnet+ftp,方案二:ssh+scp+expect. 以下主要使用ssh+scp+expect为例进行说明使用方式. 第一步:安 ...

  9. WCF中DataContract和MessageContract的区别

    一.代码案例 首选建立2个WCF Service,它们分别使用不同的Contract,同时创建一个Console控制台项目,作为Client: 其中,WcfServiceWithDataContrac ...

  10. 使用sshkey连接github等服务器

    平常使用git时因为用了https的方式,所以经常要输入密码,其实我们是可以通过这个公钥连接github git.oschina.net等服务器,这样可以省去了我们输入用户名密码这么一个步骤了. 1. ...