使用 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的开发.此消息一出,还在苦于探索自定义控件各种炫酷特效的我,兴奋地就 ...
随机推荐
- Laravel-路由组和中间件
Laravel-路由组和中间件 标签(空格分隔): php 定义路由组 Route::group(['prefix'=>'Anime'], function(){ Rout::match(['g ...
- Error creating bean with name 'testController': Injection of resource dependencies failed;
启动ssm项目报错: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 't ...
- Swift学习笔记(5):集合类型
目录: 数组:Array 集合:Set 字典:Dictionary Swift提供Array(有序集合数据).Set(无序无重复集合)和Dictionary(无序键值对集合)三种基本集合类型来存储明确 ...
- Linux 玩法
php 跑不了,只来404 同一台linux服务器上建两个网站(www.A.com, www.B.com),现在A和B都跑起来了,但只有 A 能跑 php, B只能跑静态 html 文件,不知道哪里设 ...
- UWP开发小结
做了两天的UWP开发,上手还是挺快的,不过比较郁闷的是总会被一些很简单的细节卡住很久. 首先当然是用C#修改xaml界面这个难点了,Bing搜了好久都没找到相关信息,最后还是老司机伟神指点的我.对于g ...
- PHP7内核剖析之执行流程
以fpm为例: 1.fpm启动时,会先执行 module_startup, 并随着fpm进程常驻 2.当一个请求到达之后,会执行 request_startup, 进行一些请求初始化工作,然后执行代码 ...
- 用Electron开发企业网盘(一)--通信
效果展示 项目背景: 由于浏览器的限制,web批量下载体验不好以及无法下载文件夹.采用Electron技术,通过js开发PC应用程序,着力解决批量下载.断点续传.文件夹下载等问题.配合网页版网盘使用, ...
- users---显示当前登录系统的所有用户的用户列表
users命令用于显示当前登录系统的所有用户的用户列表.每个显示的用户名对应一个登录会话.如果一个用户有不止一个登录会话,那他的用户名将显示相同的次数. 语法 users(选项) 选项 --help: ...
- laravel中soapServer支持wsdl的例子
最近在对接客户的CRM系统,获取令牌时,要用DES方式加密解密,由于之前没有搞错这种加密方式,经过请教了"百度"和"谷歌"两个老师后,结合了多篇文档内容后,终于 ...
- Linux学习之socket编程(二)
Linux学习之socket编程(二) 1.C/S模型——UDP UDP处理模型 由于UDP不需要维护连接,程序逻辑简单了很多,但是UDP协议是不可靠的,实际上有很多保证通讯可靠性的机制需要在应用层实 ...