[控件] LineAnimationView
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的更多相关文章
- JS调用Android、Ios原生控件
在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...
- HTML5 progress和meter控件
在HTML5中,新增了progress和meter控件.progress控件为进度条控件,可表示任务的进度,如Windows系统中软件的安装.文件的复制等场景的进度.meter控件为计量条控件,表示某 ...
- 百度 flash html5自切换 多文件异步上传控件webuploader基本用法
双核浏览器下在chrome内核中使用uploadify总有302问题,也不知道如何修复,之所以喜欢360浏览器是因为帮客户控制渲染内核: 若页面需默认用极速核,增加标签:<meta name=& ...
- JS与APP原生控件交互
"热更新"."热部署"相信对于混合式开发的童鞋一定不陌生,那么APP怎么避免每次升级都要在APP应用商店发布呢?这里就用到了混合式开发的概念,对于电商网站尤其显 ...
- UWP开发必备:常用数据列表控件汇总比较
今天是想通过实例将UWP开发常用的数据列表做汇总比较,作为以后项目开发参考.UWP开发必备知识点总结请参照[UWP开发必备以及常用知识点总结]. 本次主要讨论以下控件: GridView:用于显示数据 ...
- 【踩坑速记】开源日历控件,顺便全面解析开源库打包发布到Bintray/Jcenter全过程(新),让开源更简单~
一.写在前面 自使用android studio开始,就被它独特的依赖方式:compile 'com.android.support:appcompat-v7:25.0.1'所深深吸引,自从有了它,麻 ...
- 对百度WebUploader开源上传控件的二次封装,精简前端代码(两句代码搞定上传)
前言 首先声明一下,我这个是对WebUploader开源上传控件的二次封装,底层还是WebUploader实现的,只是为了更简洁的使用他而已. 下面先介绍一下WebUploader 简介: WebUp ...
- Windows API 设置窗口下控件Enable属性
参考页面: http://www.yuanjiaocheng.net/webapi/create-crud-api-1-put.html http://www.yuanjiaocheng.net/we ...
- VB.NET设置控件和窗体的显示级别
前言:在用VB.NET开发射频检测系统ADS时,当激活已存在的目标MDI子窗体时,被其他子窗体遮住了,导致目标MDI子窗体不能显示. 这个问题怎么解决呢?网上看到一篇帖子VB.NET设置控件和窗体的显 ...
随机推荐
- windows下安装并使用redis
一.安装前首先了解一下phpinfo里面的一些信息,能否正确安装非常有帮助. (下图是我的本机环境) compiler :编译器 Architecture :CPU架构 Configuration F ...
- Centos7下安装mysql5.6需要注意的点
1.自带的Mariadb和mysql冲突需要卸载. 2.原先安装过的mysql没有卸载干净会导致安装失败. 3.mysql文件夹权限需要给够,my.cnf也是一样. 4.安装过程中如果出现的其他问题很 ...
- Java 生成指定范围的随机数
/** * 生成[min, max]之间的随机整数 * * @param min 最小整数 * @param max 最大整数 * @return * @author jqlin */ private ...
- 开始使用 Vuejs 2.0 --- 组件间数据传递
Vue1.0组件间传递 使用$on()监听事件: 使用$emit()在它上面触发事件: 使用$dispatch()派发事件,事件沿着父链冒泡: 使用$broadcast()广播事件,事件向下传导给所有 ...
- 模块打包工具webpack
1.webpack的安装 1.1在安装node的基础上,npm install -g webpack(window版本,因为是全局安装,所以无所谓是哪个路径下) 1.2新建一个文件夹用于此项目 eg ...
- *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<WKWebViewConfiguration 0x1701bcd20> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the k
问题描述: ionic项目,windows下正常,打包android可正常运行: 因为需要打包到iPhone (ios 11.0.1)上测试,将代码拿到Mac OS环境下(重新npm install. ...
- sql server 运算
--Sql Server 乘法运算--select (d.RepaymentSchedule*d.MonthlyPayment) as ExpectedReceivablePayment from T ...
- 脚手架(create-react-app)没有eject情况下,使用react-scripts的时候,动态设置环境变量
在实际开发中,例如:有时候打包发布时,需要手动更新版本,比如修改package.json中的version,但是如果有时候忘了修改,那么又得build一次: 如果能动态设置多好,webpack下可以在 ...
- C Traps:运算
位移 如果sizeof(int) = 4,那么下面的代码的结果是什么? int x=255; printf("%d", x>>34); 实际输出:63 在编译这个代码时 ...
- python学习之老男孩python全栈第九期_day015知识点总结
# 作用域相关(2)locals() # 返回本地作用域中的所有名字 globals() # 返回全局作用域中的所有名字 # 迭代器/生成器相关(3)range()print('__next__' i ...