使用 Facebook开源动画库 POP 实现真实衰减动画
1. POP动画基于底层刷新原理。是基于CADisplayLink,1秒钟运行60秒,接近于游戏开发引擎
@interface ViewController ()
@property (nonatomic,strong)CADisplayLink *displayLink;
@property (nonatomic) NSInteger count;
@end
- (void)viewDidLoad {
[superviewDidLoad];
self.displayLink = [CADisplayLinkdisplay LinkWithTarget:self
selector:@selector(displayLinkEvent:)];
[self performSelector:@selector(eventOne)
withObject:nil
afterDelay:];
[self performSelector:@selector(eventTwo)
withObject:nil
afterDelay:];
}
- (void)displayLinkEvent:(id)obj
{
self.count ++;
NSLog(@"count = %ld",(long)self.count);
}
- (void)eventOne{
[self.displayLink addToRunLoop:[NSRunLoopcurrentRunLoop]forMode:NSDefaultRunLoopMode];
}
- (void)eventTwo{
[self.displayLink invalidate];
}
二、POP动画引擎中 Layer与
CALayer的联系与差别
1.使用pop动画与使用CALayer动画很相似
2.POP动画的运行没有中间状态
3.POP动画是对CALayer的动画的扩充,但不能实现全部的CALayer的动画效果
4.POP动画能够作用在不论什么对象上,不不过CALayer
- (void)accessNormalLayer{
self.normalLayer = [CALayerlayer];
,,,);
self.normalLayer.backgroundColor = [UIColorredColor].CGColor;
[self.view.layeraddSublayer:self.normalLayer];
//
CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
basicAnimation.fromValue = [NSValue valueWithCGPoint:self.normalLayer.position];
basicAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake( +,)];
basicAnimation.duration = 4.0;
basicAnimation.timingFunction = \
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
// layer的postion相当于view的center
+,);
[self.normalLayer addAnimation:basicAnimationforKey:nil];
//1.4秒移除后,动画直接到终点
[self performSelector:@selector(remoVeNormalAnimation)withObject:nilafterDelay:1.4];
}
- (void)remoVeNormalAnimation{
CALayer *layer = self.normalLayer.presentationLayer;
NSLog(@"%@",NSStringFromCGRect(layer.frame));
NSLog(@"%@",NSStringFromCGRect(self.normalLayer.frame));
[self.normalLayer removeAllAnimations];
}
三、用 POP动画引擎实现衰减动画
1.衰减动画由POPDecayAnimaiton来实现
2.须要精确计算停止运动瞬间的加速度才干用衰减动画做出真实的效果
- (void)handlePanGesture:(UIPanGestureRecognizer *)recognizer{
//获取定位点
CGPoint translation = [recognizer translationInView:self.view];
//recognizer.view.center
指的是button
recognizer.view.center =CGPointMake(recognizer.view.center.x + translation.x,
recognizer.view.center.y +translation.y);
//让他恢复坐标系
[recognizer setTranslation:CGPointMake(,)inView:self.view];
if (recognizer.state ==UIGestureRecognizerStateChanged) {
NSLog(@"手势停止时运行这一句话");
//获取加速度
CGPoint velocity = [recognizer velocityInView:self.view];
//初始化POP的deacy(衰减)动画
POPDecayAnimaton *decayAnimation = \
[POPDecayAnimation animationWithPropertyName:kPOPLayerPosition];
decayAnimation.velocity = [NSValue valueWithCGPoint:velocity];
[recognizer.view.layer pop_addAnimation:decayAnimation forKey:nil];
}
}
- (void)buttonEvent:(UIButton *)button
{
//[button.layer pop_removeAllAnimations];
}
- (void)viewDidLoad {
[superviewDidLoad];
,,,)];
self.button .backgroundColor = [UIColorredColor];
;
self.button.layer.masksToBounds =YES;
self.button.center =self.view.center;
[self.viewaddSubview:self.button];
[self.buttonaddTarget:self
action:@selector(buttonEvent:)
forControlEvents:UIControlEventTouchDragInside];
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizeralloc]initWithTarget:selfaction:@selector(handlePanGesture:)];
[self.buttonaddGestureRecognizer:panGesture];
}
Facebook官方的pop动画:附链接https://github.com/schneiderandre/popping
使用 Facebook开源动画库 POP 实现真实衰减动画的更多相关文章
- Facebook 开源动画库 pop
官网:https://github.com/facebook/pop Demo: https://github.com/callmeed/pop-playground 一:pop的基本构成: POPP ...
- Facebook开源动画库 POP-POPBasicAnimation运用
动画在APP开发过程中还是经常出现,将花几天的时间对Facebook开源动画库 POP进行简单的学习:本文主要针对的是POPBasicAnimation运用:实例源代码已经上传至gitHub,地址:h ...
- Facebook开源动画库 POP-小实例
实例1:图片视图跟着手在屏幕上的点改变大小 - (void)viewDidLoad { [super viewDidLoad]; //添加手势 UIPanGestureRecognizer *gest ...
- Facebook开源动画库 POP-POPDecayAnimation运用
关于POPDecayAnimation的介绍先引用别人写的一些内容,基本上把它的一些注意点都说明了: Decay Animation 就是 POP 提供的另外一个非常特别的动画,他实现了一个衰减的效果 ...
- Facebook开源动画库 POP-POPSpringAnimation运用
POPSpringAnimation也许是大多数人使用POP的理由 其提供一个类似弹簧一般的动画效果:实例源代码已经上传至gitHub,地址:https://github.com/wujunyang/ ...
- rebound是facebook的开源动画库
网址:http://www.jcodecraeer.com/a/opensource/2015/0121/2338.html 介绍: rebound是facebook的开源动画库.可以认为这个动画库是 ...
- 第三方开源动画库EasyAnimation中一个小bug的修复
看过iOS动画之旅的都知道,其中在最后提到一个作者写的开源动画库EasyAnimation(以下简称EA). EA对CoreAnimation中的view和layer动画做了更高层次的包装和抽象,使得 ...
- [转] iOS 动画库 Pop 和 Canvas 各自的优势和劣势是什么?
iOS 动画库 Pop 和 Canvas 各自的优势和劣势是什么? http://www.zhihu.com/question/23654895/answer/25541037 拿 Canvas 来和 ...
- Lottie安卓开源动画库使用
碉堡的Lottie Airbnb最近开源了一个名叫Lottie的动画库,它能够同时支持iOS,Android与ReactNative的开发.此消息一出,还在苦于探索自定义控件各种炫酷特效的我,兴奋地就 ...
随机推荐
- if语句练习
输入年月日,首先判断该年是平年闰年并且计算该天是该年的第几天: 判断男女体重是否标准: 体重判断里边出现一个问题:如果性别输入的不是男也不是女,那么会执行输出“请输入正确的性别”:然后底下会继续输出“ ...
- PostgreSQL Replication之第八章 与pgbouncer一起工作(5)
8.5 维护 pgbouncer 除了我们在本章已经说明的,pgbouncer有一个很好的能够执行基本管理和监控任务的交互式管理界面. 它是如何工作的呢?pgbouncer提供给您一个虚假的称为pgb ...
- bzoj3252: 攻略 优先队列 并查集 贪心
考场上自己yy出来的做法..... Code: #include<cstdio> #include<algorithm> #include<queue> #incl ...
- vue中的三级联动
1.template里面的内容 2.js里面的内容 3.函数怎么写? 这是一个省市区的三级联动,首先你要传递中国的id,这样才能获取到所有的省份,所以在vue的项目中,我需要发一次进页面就请求(来得到 ...
- 隐藏div,文本框角圆滑,消除外边框
#div_1 /*将div设置完成,并且隐藏,当需要的时候对其属性值进行修改*/ { height: 36px; width: 1099px; background-color: #F0DFDF; m ...
- MySQL 大数据量文本插入
导入几万条数据需要等好几分钟的朋友来围观一下! 百万条数据插入,只在一瞬间.呵呵夸张,夸张!! 不到半分钟是真的! 插入指令: load data infile 'c:/wamp/tmp/Data_O ...
- UVA-10200 Prime Time 素数(注意除法精度)
题目链接:https://cn.vjudge.net/problem/UVA-10200 题意 给出一个公式$ m=n^2+n+41, n \in Z^+ $ 现在$ a,b\in[0, 10000] ...
- man帮助
man命令是Linux下的帮助指令,通过man指令可以查看Linux中的指令帮助.配置文件帮助和编程帮助等信息.
- 20180929 北京大学 人工智能实践:Tensorflow笔记01
北京大学 人工智能实践:Tensorflow笔记 https://www.bilibili.com/video/av22530538/?p=13 (完)
- 一个Web报表项目的性能分析和优化实践(三) :提高Web应用服务器Tomcat的内存配置,并确认配置正确
摘要 上一篇,一个Web报表项目的性能分析和优化实践(一):小试牛刀,统一显示SQL语句执行时间 ,讲述了项目优化的整体背景,重点讲述了统一显示了Web项目SQL语句的执行时间. 本篇,将重点介绍提高 ...