效果图:

#import "ViewController.h"
#import <POP.h> @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; // 初始化按钮
UIButton *btn = [UIButton buttonWithType:UIButtonTypeContactAdd];
btn.center = self.view.center;
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn]; // 初始化拖拽手势
UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(btnPan:)];
[btn addGestureRecognizer:pan]; } - (void)btnPan:(UIPanGestureRecognizer *)recognizer
{
// 获取手指移动后的位置
CGPoint translation = [recognizer translationInView:self.view]; UIButton *btn = (UIButton *)recognizer.view;
btn.center = CGPointMake(btn.center.x + translation.x, btn.center.y + translation.y); // 复位, 否则手势会保留上一次的状态
[recognizer setTranslation:CGPointMake(, ) inView:self.view]; if (recognizer.state == UIGestureRecognizerStateEnded) { // 手势结束
// 初始化POP的衰减动画
POPDecayAnimation *decay = [POPDecayAnimation animationWithPropertyNamed:kPOPLayerPosition];
// 设置加速度值
decay.velocity = [NSValue valueWithCGPoint:[recognizer velocityInView:self.view]];
// 添加动画
[btn.layer pop_addAnimation:decay forKey:nil];
}
} // 点击按钮时移除所有POP动画
- (void)btnClick:(UIButton *)btn
{
[btn.layer pop_removeAllAnimations];
} @end

github:https://github.com/RinpeChen/POPDecayAnimationDemo

用POP动画引擎实现衰减动画(POPDecayAnimation)的更多相关文章

  1. 用POP动画引擎实现弹簧动画(POPSpringAnimation)

    效果图: #import "ViewController.h" #import <POP.h> @interface ViewController () @proper ...

  2. 使用 Facebook开源动画库 POP 实现真实衰减动画

    1. POP动画基于底层刷新原理.是基于CADisplayLink,1秒钟运行60秒,接近于游戏开发引擎 @interface ViewController () @property (nonatom ...

  3. [译]理解 Windows UI 动画引擎

    本文译自 Nick Waggoner 的 "Understand what’s possible with the Windows UI Animation Engine",已获原 ...

  4. 聊聊动画引擎 pop

    iOS可以通过CADisplayLink实现自定义动画引擎,pop就是基于此实现的,而且比原生Core Animation更强大好用.譬如当ViewController侧滑返回的时候,系统会将Core ...

  5. POP动画引擎中Layer与CALayer的一点区别

    POP动画引擎是facebook提供的一个开源框架, 可以实现很多的动画效果, 这里就不一一介绍啦, 有兴趣的童鞋请移步: https://github.com/facebook/pop 下面简单的讲 ...

  6. SpriteSheet精灵动画引擎

    SpriteSheet精灵动画引擎   本文介绍Flash中SpriteSheet精灵序列图与其它渲染方式的性能对比.SpriteSheet的原理及注意实现,最后实现了一个精灵序列图的渲染引擎.本文的 ...

  7. Unity3d动画脚本 Animation Scripting(深入了解游戏引擎中的动画处理原理)

    也许这一篇文章的内容有点枯燥,但我要说的是如果你想深入的了解游戏引擎是如何处理动画片断或者素材并 让玩家操控的角色动起来栩栩如生,那么这真是一篇好文章(当然我仅仅是翻译了一下)   动画脚本 Anim ...

  8. 第四十二课:基于CSS的动画引擎

    由于低版本浏览器不支持css3 animation,因此我们需要根据浏览器来选择不同的动画引擎.如果浏览器支持css3 animation,那么就使用此动画引擎,如果不支持,就使用javascript ...

  9. iOS_SN_push/pop转场动画封装和一般动画封装

    封装类中的方法: #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface AnimationE ...

随机推荐

  1. 查看memcached中最大生存时间

    如果想看一下线上服务器上存储时间最久的key是多长时间,又没有memcached-tool工具可用的话,可以使用这个命令 stats items 执行结果如下: stats items :number ...

  2. linux c数据库备份第三版

    这个版本相对第一版更新了很多,其实我本地定义为第五版的.相对第一版主要更新内容:1.增加了定时器2.用户可以停止调备份程序3.如果备份程序正在运行,那么尝试运行提示已经在运行4.记录程序运行时的pid ...

  3. Python中函数参数传递问题

    先上两个例子: http://python.jobbole.com/85231/ a = 1 def fun(a): a = 2 fun(a) print a # 结果为1 fun(a)中的a,可以看 ...

  4. IOS--UIAlertView的使用方法详细

    IOS--UIAlertView的使用方法详细   // UIAlertView的常用方法 // 标准样式 UIAlertView *oneAlertView = [[UIAlertView allo ...

  5. 倒水问题-->经典面试题目

    题目详细: 有两个容器,容积分别为A升和B升,有无限多的水,现在需要C升水.我们还有一个足够大的水缸,足够容纳C升水.起初它是空的,我们只能往水缸里倒入水,而不能倒出.可以进行的操作是:把一个容器灌满 ...

  6. Mac中的快捷键

    Mac中主要有四个修饰键,分别是Command,Control,Option和Shift,这四个键分别有自己的图案 基本快捷键 Command是Mac里最重要的修饰键,在大多数情况下相当于Window ...

  7. (?m) 可以让.去匹配换行

    <pre name="code" class="html"># User@Host: zjzc_app[zjzc_app] @ [10.171.24 ...

  8. 【HDOJ】1244 Max Sum Plus Plus Plus

    这题目一直wa,原来是因为我把JUDGE写错了,对拍了一下午都没检查出来.水DP啊. #include <cstdio> #include <cstring> #include ...

  9. call-template和apply-templates

    对xml模板 来说,name属性是很关键的 call-template /apply-template 的name必须要和模板的name相对应.模板相当于一个函数,可以暂时这么看.而name相当于函数 ...

  10. Linux----硬连接和软连接

    一,概念 在Linux的文件系统中,保存在磁盘分区中的文件不管是什么类型都给它分配一个编号称为索引节点号(Inode Index). 硬链接 多个文件名指向同一个索引节点(一个文件有多个副本) 允许一 ...