用POP动画引擎实现衰减动画(POPDecayAnimation)
效果图:

#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)的更多相关文章
- 用POP动画引擎实现弹簧动画(POPSpringAnimation)
效果图: #import "ViewController.h" #import <POP.h> @interface ViewController () @proper ...
- 使用 Facebook开源动画库 POP 实现真实衰减动画
1. POP动画基于底层刷新原理.是基于CADisplayLink,1秒钟运行60秒,接近于游戏开发引擎 @interface ViewController () @property (nonatom ...
- [译]理解 Windows UI 动画引擎
本文译自 Nick Waggoner 的 "Understand what’s possible with the Windows UI Animation Engine",已获原 ...
- 聊聊动画引擎 pop
iOS可以通过CADisplayLink实现自定义动画引擎,pop就是基于此实现的,而且比原生Core Animation更强大好用.譬如当ViewController侧滑返回的时候,系统会将Core ...
- POP动画引擎中Layer与CALayer的一点区别
POP动画引擎是facebook提供的一个开源框架, 可以实现很多的动画效果, 这里就不一一介绍啦, 有兴趣的童鞋请移步: https://github.com/facebook/pop 下面简单的讲 ...
- SpriteSheet精灵动画引擎
SpriteSheet精灵动画引擎 本文介绍Flash中SpriteSheet精灵序列图与其它渲染方式的性能对比.SpriteSheet的原理及注意实现,最后实现了一个精灵序列图的渲染引擎.本文的 ...
- Unity3d动画脚本 Animation Scripting(深入了解游戏引擎中的动画处理原理)
也许这一篇文章的内容有点枯燥,但我要说的是如果你想深入的了解游戏引擎是如何处理动画片断或者素材并 让玩家操控的角色动起来栩栩如生,那么这真是一篇好文章(当然我仅仅是翻译了一下) 动画脚本 Anim ...
- 第四十二课:基于CSS的动画引擎
由于低版本浏览器不支持css3 animation,因此我们需要根据浏览器来选择不同的动画引擎.如果浏览器支持css3 animation,那么就使用此动画引擎,如果不支持,就使用javascript ...
- iOS_SN_push/pop转场动画封装和一般动画封装
封装类中的方法: #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> @interface AnimationE ...
随机推荐
- 简化的nginx多进程模型demo
//version 1:以下代码仅演示nginx多进程模型[test@vm c]$ cat mynginx.c#include <stdio.h> #include <string. ...
- IOS--UIActivityIndicatorView的使用方法详细
IOS--UIActivityIndicatorView的使用方法详细 // UIActivityIndicatorView的常用方法 活动指示器,就是旋转进度轮 UIActivityIndica ...
- protractor protractor.conf.js [launcher] Process exited with error code 1 undefined:1190
y@y:karma-t01$ protractor protractor.conf.js [launcher] Process exited with error code undefined: vl ...
- MVC4 教程
http://blog.csdn.net/huangjihua0402/article/details/8507055 http://www.cnblogs.com/lc-chenlong/p/324 ...
- zoj 3787 Access System
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5274 #include <cstdio> #include < ...
- poj 2513Colored Sticks
http://poj.org/problem?id=2513 #include<cstdio> #include<cstdlib> #include<cstring> ...
- 【细说Java】Java封箱拆箱的一些问题
1.概念 首先简单介绍一下概念性的东西: 所谓封箱:就是把基本类型封装成其所对应的包装类型: 而拆箱则恰好相反,是把包装类型转换成其所对应的基本数据类型. 如基本类型int,封箱后的包装类是Integ ...
- 在 Windows 下远程桌面连接 Linux - XManager 篇
XManager是一个简单易用的高性能的运行在Windows平台上的X-Server软件,而Gnome和KDE就是X-Client,Linux下的X-Server则为Xorg.它能把远端Unix/Li ...
- HDOJ 1016 Prime Ring Problem素数环【深搜】
Problem Description A ring is compose of n circles as shown in diagram. Put natural number 1, 2, -, ...
- Java 设计模式实现 不错的引用
这段时间有兴趣重新温习一下设计模式在Java中的实现,碰巧看到一个不错的设计模式总结,这里引用一下作为参考. 创建型模式: JAVA设计模式-Singleton JAVA设计模式-Factory JA ...