使用facebook开源动画库pop实现真实衰减动画

blfbuaa blfbuaa     2022-09-04     522

关键词:

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:1];

    

    [self performSelector:@selector(eventTwo)

               withObject:nil

               afterDelay:2];

}


- (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.frame =CGRectMake(100,100,100,100);

    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(100 +50,400)];

    basicAnimation.duration     = 4.0;

    basicAnimation.timingFunction =

    [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];

    // layerpostion相当于viewcenter

    self.normalLayer.position =CGPointMake(100 +50,400);

    

    [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(0,0)inView:self.view];

    

    if (recognizer.state ==UIGestureRecognizerStateChanged) {

        NSLog(@"手势停止时运行这一句话");

        //获取加速度

        CGPoint velocity = [recognizer velocityInView:self.view];

        //初始化POPdeacy(衰减)动画

        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 = [[UIButton alloc]initWithFrame:CGRectMake(100,100,100,100)];

    self.button .backgroundColor = [UIColorredColor];

    self.button.layer.cornerRadius =50;

    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





如何手动导入pop动画库

...发布时间】:2016-06-1209:40:45【问题描述】:我的项目没有使用cocoapod,手动导入总是出错。dyld:Librarynotloaded:@rpath/pop.framework/popReferencedfrom:/Users/wajiu/Library/Developer/CoreSimul 查看详情

android动画使用开源动画库nineoldandroids

       Android系统支持原生动画,这为应用开发者开发绚丽的界面提供了极大的方便,有时候动画是很必要的,当你想做一个滑动的特效的时候,如果苦思冥想都搞不定,那么你可以考虑下动画,说不定... 查看详情

animy.js,自己编写的功能丰富的html动画库

...各种js动画。比方移动、拉升、变色等等,全部动画经常使用的功能都已经实现,比方播放、暂停、停止、循环、加速、减速、反向播放、缓动、路径动画、锚点动画、复合动画、叠加动画等等。由于CSDN里面不方便直接插入js代... 查看详情

velocity.js动画库使用

...作,并和$.animate()有相同的API,但它不依赖jQuery,可单独使用。  2、兼容性可兼容到IE8和Android2.3。若需要兼容IE8,就必须引入jQuery1.x 3、示例代码(注意文件引用路径)(1)index.html<!DOCTYPEhtm 查看详情

lottie,一个强大的移动端动画库

...的每一帧动画实现高效流畅的效果,本文简单介绍其使用,以帮助读者更好的理解。通过Gradle添加依赖dependenciescompile'com.airbnb.android:lottie:2.1.0'使用方式一:XML加载&l 查看详情

uni-app引入css动画库

引入Animate动画库Animate中文网地址:http://www.animate.net.cn/Animate下载地址:https://daneden.github.io/animate.css/下载Animate.css在app.vue中引入动画库使用动画库:animated+动画End! 查看详情

css3常用动画+动画库

...淡出效果,如果你想快速的整合各种CSS3动画特效的话,使用它即可方便的实现。 查看演示:https://daneden.github.io/animate.css/ github地址:https://githu 查看详情

第三方动画库使用方法

第三方动画库的使用1.名字叫:animate.css2.封装了很多工作中常用的动画3.在使用第三方时候,需要加上animated类名首先https://daneden.github.io/animate.css/下载animate.csslink进head中第一种方法<divclass="myWorld">我的世界</div><style>.my... 查看详情

wpfloading加载动画库

原文:WPFloading加载动画库 1.下载Dll??????https://pan.baidu.com/s/1wKgv5_Q8phWo5CrXWlB9dA2.在项目中添加引用???????略3.在Xaml中引入名称空间?????xmlns:myLib="clr-namespace:MyLoadingLib;assembly=MyLoadingLib"4.使用代码??? 查看详情

用javascript实现三次贝塞尔动画库-前端组件化(代码片段)

...发现其他的参数都用上了。但是timingFunction我们是还没有使用上的。这里我们就来一起处理这个问题。timingFucntion这个逻辑主要是用在Animation的run方法中。如果大家还记得之前的一篇讲解CSS动画的文章,里面我们了解到三次贝... 查看详情

css3动画库收集

 1.animate.css–齐全的CSS3动画库http://www.dowebok.com/98.html 2.Angular官方动画库http://augus.github.io/ngAnimate/git地址:https://github.com/Augus/ngAnimate  查看详情

41vue使用第三方动画库(代码片段)

[动画]如何在Vue中使用第三方动画库Animate.css阐述自定义动画选择方法一:给transition标签一个name方法二:自行制定CSS选择名称使用第三方动画库总结阐述这节我们一起学习一下,如何在Vue中使用第三方动画库Animate.css... 查看详情

aos.js超赞页面滚动元素动画jquery动画库

aos.js超赞页面滚动元素动画jQuery动画库插件描述:aos.js 是一款效果超赞的页面滚动元素动画jQuery动画库插件。该动画库可以在页面滚动时提供28种不同的元素动画效果,以及多种easing效果。在页面往回滚动时,元素会恢复到... 查看详情

Flex / Actionscript 中的文本动画库? [关闭]

...介绍屏幕或横幅)的酷文本动画效果库。我已经放弃尝试使用Flash本身,因为这需要很长时间,而且我不知道从众多Flash文本动画工具中选择哪一个。我希望能 查看详情

3.vue中导入animate.css动画库swiper轮播图组件

1.vue中导入animate.css动画库       2.vue中使用Swiper轮播图插件        注意:swiper常用设置     查看详情

react-native 动画库的流类型

...问题描述】:我正在尝试将react-native的Animated库与Flow一起使用。不幸的是,我遇到了一堆无法解决的Flow错误(请参阅屏幕截图)。在下面的示例中,我在屏幕上渲染了一个圆圈,并希望在使用Animated.spring渲染它时使其移 查看详情

animate.css_css3动画库介绍

插件描述:Animate.css内置了很多典型的css3动画,兼容性好使用方便。Animate.css是一个有趣的,跨浏览器的css3动画库。很值得我们在项目中引用。用法1、首先引入animatecss文件123<head>  <link rel="stylesheet" href="anim... 查看详情

动画库animate.css的用法

简介animate.css是一个来自国外的CSS3动画库,它预设了引起弹跳(bounce)、摇摆(swing)、颤抖(wobble)、抖动(shake)、闪烁(flash)、翻转(flip)、旋转(rotate)、淡入淡出(fade)、滑动(Sliding)、光速(lightspeed)、缩放变... 查看详情