使用 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的开发.此消息一出,还在苦于探索自定义控件各种炫酷特效的我,兴奋地就 ...
随机推荐
- nyoj--42--一笔画问题(并查集)
一笔画问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 zyc从小就比较喜欢玩一些小游戏,其中就包括画一笔画,他想请你帮他写一个程序,判断一个图是否能够用一笔画下来. ...
- hpuoj--校赛--与学妹滑雪(最短路+精度判断)
问题 G: 感恩节KK专场--与学妹滑雪 时间限制: 1 Sec 内存限制: 128 MB 提交: 284 解决: 25 [提交][状态][讨论版] 题目描述 这周下的雪好大好大,不过这正和KK学 ...
- linux中的挂载是什么意思?通俗点讲
mount /dev/sda1 /mnt解释:mount 就是挂载命令,/dev/sda1是要挂载的磁盘分区,/mnt是要绑定的目录挂载后就能到目录/mnt去访问磁盘分区/dev/sda1里面的资料了 ...
- AS3 常见问题
SharedObject 不起作用(exe, air中) var so:SharedObject = SharedObject.getLocal("aa", "/&quo ...
- 4、Go for循环
package main import "fmt" func main(){ //for 循环是go语言唯一的循环结构,分为三种类型 //第一种 类似while i:=1 for ...
- P4287 [SHOI2011]双倍回文(回文树)
题目描述 记字符串 w 的倒置为 w^R^ .例如 (abcd)^R^=dcba , (abba)^R^=abba . 对字符串x,如果 x 满足 x^R^=x ,则称之为回文:例如abba是一个回文 ...
- Jeff Dean专访,有不少干货
<专访Jeff Dean:我们要推动机器学习再上一层楼> 文件链接如下: Link https://arxiv.org/ 有意思的是,里面提到的 arXiv网站,一个能够用来证明论文上传时 ...
- mysql生成随机时间
mysql> update test set create_time=concat('2013-10-01 ', floor(10+rand()*10),':',floor(10+rand()* ...
- BZOJ 1002 FJOI 2007 轮状病毒 暴力+找规律+高精度
题目大意: 思路:基尔霍夫矩阵求生成树个数,不会. 可是能够暴力打表.(我才不会说我调试force调试了20分钟... CODE(force.cc): #include <cstdio> ...
- FZOJ 2176 easy problem ( 树链剖分 )
pid=2176" target="_blank">题目链接~~> 做题感悟:感觉做多了树链剖分的题目,有很多是树链剖分 + 想法.. 解题思路: 这题非常明 ...