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 实现真实衰减动画的更多相关文章

  1. Facebook 开源动画库 pop

    官网:https://github.com/facebook/pop Demo: https://github.com/callmeed/pop-playground 一:pop的基本构成: POPP ...

  2. Facebook开源动画库 POP-POPBasicAnimation运用

    动画在APP开发过程中还是经常出现,将花几天的时间对Facebook开源动画库 POP进行简单的学习:本文主要针对的是POPBasicAnimation运用:实例源代码已经上传至gitHub,地址:h ...

  3. Facebook开源动画库 POP-小实例

    实例1:图片视图跟着手在屏幕上的点改变大小 - (void)viewDidLoad { [super viewDidLoad]; //添加手势 UIPanGestureRecognizer *gest ...

  4. Facebook开源动画库 POP-POPDecayAnimation运用

    关于POPDecayAnimation的介绍先引用别人写的一些内容,基本上把它的一些注意点都说明了: Decay Animation 就是 POP 提供的另外一个非常特别的动画,他实现了一个衰减的效果 ...

  5. Facebook开源动画库 POP-POPSpringAnimation运用

    POPSpringAnimation也许是大多数人使用POP的理由 其提供一个类似弹簧一般的动画效果:实例源代码已经上传至gitHub,地址:https://github.com/wujunyang/ ...

  6. rebound是facebook的开源动画库

    网址:http://www.jcodecraeer.com/a/opensource/2015/0121/2338.html 介绍: rebound是facebook的开源动画库.可以认为这个动画库是 ...

  7. 第三方开源动画库EasyAnimation中一个小bug的修复

    看过iOS动画之旅的都知道,其中在最后提到一个作者写的开源动画库EasyAnimation(以下简称EA). EA对CoreAnimation中的view和layer动画做了更高层次的包装和抽象,使得 ...

  8. [转] iOS 动画库 Pop 和 Canvas 各自的优势和劣势是什么?

    iOS 动画库 Pop 和 Canvas 各自的优势和劣势是什么? http://www.zhihu.com/question/23654895/answer/25541037 拿 Canvas 来和 ...

  9. Lottie安卓开源动画库使用

    碉堡的Lottie Airbnb最近开源了一个名叫Lottie的动画库,它能够同时支持iOS,Android与ReactNative的开发.此消息一出,还在苦于探索自定义控件各种炫酷特效的我,兴奋地就 ...

随机推荐

  1. java9新特性-17-智能Java编译工具

    1.官方Feature 139: Enhance javac to Improve Build Speed. 199: Smart Java Compilation, Phase Two 2.使用说明 ...

  2. jsp输出当前时间

    在jsp页面中输出完整的时间,格式为"年 月 日  时:分:秒" <% Date date = new Date(); SimpleDateFormat t = new Si ...

  3. 洛谷2850 【Usaco2006 Dec】虫洞Wormholes SPFA

    问题描述 John在他的农场中闲逛时发现了许多虫洞.虫洞可以看作一条十分奇特的有向边,并可以使你返回到过去的一个时刻(相对你进入虫洞之前).John的每个农场有M条小路(无向边)连接着N (从1..N ...

  4. [POI2009]KON-Ticket Inspector(二维前缀和+DP)

    题意 有n个车站,现在有一辆火车从1到n驶过,给出aij代表从i站上车j站下车的人的个数.列车行驶过程中你有K次检票机会,所有当前在车上的人会被检票,问最多能检多少个不同的人的票 (n<=600 ...

  5. keytool常用操作

    keytool 秘钥需要存储在秘钥库中,秘钥库可以理解为一个存储了一个或多个秘钥的文件.一个秘钥库可以存储多个密钥对,每个秘钥对你都需要给他们取一个名字. D:\software\Java\jdk1. ...

  6. JDBC连接SQL Server遇到的问题

    需要使用到微软的JDBC sql server的驱动类,去官网下载jar包 使用的URL模式:"jdbc:sqlserver:地址:端口//;databaseName=YourDatabas ...

  7. 今日SGU 6.6

    sgu 177 题意:给你一个一开始全是白色的正方形,边长为n,然后问你经过几次染色之后,最后的矩形里面 还剩多少个白色的块 收获:矩形切割,我们可以这么做,离散处理,对于每次染黑的操作,看看后面有没 ...

  8. [HAOI2006]旅行(并查集)

    寒假填坑五十道省选题——第五道 [HAOI2006]旅行 题目描述 Z小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光.Z小镇附近共有N个景点(编号为1,2,3,…,N),这些景点被M条道路 ...

  9. Python中的list,tuple,dict和set

    List list的创建与检索 Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时添加和删除其中的元素. 构造list非常简单,直接用 [ ] 把list的所有元素都括 ...

  10. django-xadmin使用之配置页眉页脚

    环境:xadmin-for-python3 python3.5.2 django1.9.12 在模块的adminx.py文件中增加以下代码即可: # TIP 定义页头页脚 class GlobalSe ...