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. border:none与border:0的区别

    border:none与border:0的区别体现为两点:一是理论上的性能差异,二是浏览器兼容性的差异. 性能差异: [border:0;]把border设为“0”像素效果等于border-width ...

  2. VS自定义开发向导中的vsdir文件的简单说明

    作者:朱金灿 来源:http://blog.csdn.net/clever101 VS自定义开发向导中有一个vsdir文件.这个文件指定了在VS中项目的标题.默认工程名等内容.下面对vsdir文件做一 ...

  3. NodeJS学习笔记 (31)定时器-timers

    https://github.com/chyingp/nodejs-learning-guide

  4. js数组去重问题

    1. 双层循环:外层循环,内层比较值: (1)利用splice直接在原数组进行操作 Array.prototype.delRepeat = function (){ var arr = this; v ...

  5. 常用模块(hashlib、suprocess、configparser)

    hashlib模块 hash是一种接受不了内容的算法,(3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法),该算 ...

  6. centeros安装jdk

    准备工作: java se下载网址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.ht ...

  7. caioj 1084 动态规划入门(非常规DP8:任务安排)(取消后效性)

    这道题的难点在于,前面分组的时间会影响到后面的结果 也就是有后效性,这样是不能用dp的 所以我们要想办法取消后效性 那么,我们就可以把影响加上去,也就是当前这一组加上了s 那么就把s对后面的影响全部加 ...

  8. WHU 1540 Fibonacci 递推

    武大邀请赛的网络预选赛,就去做了个签到题,居然连这个递推都没推出来,真是惭愧. 而且好久没写矩阵乘法了,来回顾一下. 题意: 求Fibonacci数列的,前n项立方和. 思路: 可以求得一下递推公式: ...

  9. cocos2d-x 3.1.1学习笔记[23]寻找主循环 mainloop

    文章出自于  http://blog.csdn.net/zhouyunxuan cocos2d到底是怎样把场景展示给我们的,我一直非常好奇. 凭个人猜想,引擎内部的结构类似于这样 while(true ...

  10. vue4 属性 class style

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...