使用 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的开发.此消息一出,还在苦于探索自定义控件各种炫酷特效的我,兴奋地就 ...
随机推荐
- [poj 2912] Rochambeau 解题报告 (带权并查集)
题目链接:http://poj.org/problem?id=2912 题目: 题目大意: n个人进行m轮剪刀石头布游戏(0<n<=500,0<=m<=2000) 接下来m行形 ...
- java动态导出PDF(利用itext)
项目基于ssm框架,使用itext动态导出pdf文件: 1.引入两个jar包:itextpdf-5.5.5.jar.itext-asian-5.2.0.jar 说明: 1.itextpdf-5.5.5 ...
- iOS: 零误差或极小误差的定时执行或延迟执行?
问题如下: 节奏类游戏需要执行很多的跟音乐节拍相关的操作,并且为了保证节奏感,需要让操作跟节拍的关系十分紧密.对两者间隔要求不能超过0.02秒或更低. 目前使用了 GCD 中的 asyncAfter( ...
- 三分钟明白 Activiti工作流 -- java运用_转载
一. 什么是工作流 以请假为例,现在大多数公司的请假流程是这样的 员工打电话(或网聊)向上级提出请假申请——上级口头同意——上级将请假记录下来——月底将请假记录上交公司——公司将请假录入电脑 采用工作 ...
- HDU 4398 Template Library Management (最优页面调度算法)
中等偏易题.操作系统理论中的最优页面调度算法,贪心.当需要淘汰某个模版时,淘汰掉当前手中在最远的将来才会被用到(或者以后永远不再用到)的那个. 代码: #include <iostream> ...
- web——前后端通信原理
前端向后台传输数据: 传输方法:post get 区别: (1)get:用于从服务器获取数据,将参数数据队列加到提交表单的ACTION属性所指的URL中,值和表单内各个字段一一对应,在URL中可以看 ...
- Android——4.2 - 3G移植之路之 AT 通信 (四)
在前文Android--4.2 - 3G移植之路之 reference-ril .pppd 拨号上网 (三)中分析了3G连接网络的流程,当中有说道通过AT指令建立连接, 在这里记录一下3G中的AT通信 ...
- mysql查询今天,昨天,近7天,近30天,本月,上一月数据
近期项目中用到了查询当月数据记录的功能,最初的想法是在逻辑业务里构造好时间段进行查询,当写sql语句时感觉挺麻烦.所以就到网上搜索了一下,看看是不是能有简单的方法.果然.网络资源非常强大.以下结合我的 ...
- Hive Cilent数据操作
Hive运行命令方式有cli,jdbc.hwi.beeline.而我们经常使用的往往是cli shell 操作. cli shell hive -help hive --help 注:命令脚本必须在集 ...
- [9]EC_屏蔽ecshop云提示no_license
安装完后,打开后台就看到这个,特别烦,想立刻干掉它. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdXB0b255dWFu/font/5a6L5L2T/f ...