效果图:

#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. TCP\UDP链接的异同

    简单的说TCP与UDP的区别是有无连接状态.TCP是有连接状态的,而UDP没有,所以TCP是一种比较安全的通讯协议,而UDP则比较方便 TCP 127.0.0.1:1026 0.0.0.0:0 LIS ...

  2. Raspberry PI Model B+ (LCD显示CPU温度)

    Title:Raspberry PI Model B+ (LCD显示CPU温度)  --2015-01-29 17:44 买了块连接Raspberry PI Model B+的LCD显示器,上面没写C ...

  3. Android Service之LOCATION_SERVICE

    Android提供了GPS功能 LocationManager obj = (LocationManager)getSystemService(Context.LOCATION_SERVICE) Pe ...

  4. Android JSON,Gson,fastjson实现比较

    activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&qu ...

  5. CONTEXT MENU简介

    安卓中的上下文菜单是通过长按控件元素触发的,要注意的是每次都会触发onCreateContextMenu方法: main.xml <?xml version="1.0" en ...

  6. Qt for Android 开发大坑123

    http://blog.csdn.net/qyvlik/article/details/50989685 http://blog.csdn.net/qyvlik/article/details/515 ...

  7. PF_NETLINK应用实例NETLINK_KOBJECT_UEVENT具体实现--udev实现原理

    PF_NETLINK应用实例NETLINK_KOBJECT_UEVENT具体实现--udev实现原理 相对于linux来说,udev还是一个新事物.然而,尽管它03年才出现,尽管它很低调(J),但它无 ...

  8. Android新浪微博客户端(四)——添加多个账户及认证

    原文出自:方杰| http://fangjie.info/?p=75转载请注明出处 二.获取用户信息并保存数据库 上面说到加载AuthActivity有两种情况,其中一种就是授权成功回调,在授权回调成 ...

  9. HDU5406---CRB and Apple( DP) 2015 Multi-University Training Contest 10

    题意比较简单, dp[i][j] 表示上一次男女吃的deliciousness分别为i, j的时候的吃的最多的苹果. 那么dp[i][j] = max(dp[i][k] + 1),   0 < ...

  10. 《鸟哥Linux私房菜基础学习篇》命令索引

    在学习的过程,由于很多命令平时都用不着,因此做这个索引方便需要时查找.这包括了前两部分.主要是按页码顺序. P118 date:显示日期与时间 cal:显示日历 bc:计算器 P121 [Tab]:命 ...