编者注:用Origami作iOS动效的同学如果愁怎么实现,可以把这个给开发看看作为参考哦

如果说Origami这款动效原型工具是Facebook Paper的幕后功臣,那么POP便是Origami的地基。感谢Facebook开源了POP动效库,让人人都能制作出华丽的动效。我们只需5步,便能搞定酷炫的动效。

步骤1: 安装

使用CocoaPods安装POP,只需要在Podfile中加入这么一行:

pod 'pop', '~> 1.0'

或者如果想要手动添加,那么参考POP Github中的描述:

除此之外,你还可以将工程添加到工作区里面,然后采用提供的配制文件。或者手动复制POP子目录下的文件,复制到工程里面。如果选择手动安装,确保C++标准库链入其中,只需要在项目链接标记中包含 -lc++即可。

Facebook POP动效库:https://github.com/facebook/pop

如果不懂得如何使用CocoaPods,请看这个教程:

CocoaPods简易使用指南

步骤2: 将POP加入到工程中

在工程开头添加如下:

#import <POP/POP.h>

步骤 3:创建动效

使用POP可以创建4类动效:: spring, decay, basic and custom.

Spring (弹性)动效可以赋予物体愉悦的弹性效果

POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];

Decay (衰减) 动效可以用来逐渐减慢物体的速度至停止

POPDecayAnimation *anim = [POPDecayAnimation animationWithPropertyNamed:kPOPLayerPositionX];

Basic(基本)动效可以在给定时间的运动中插入数值调整运动节奏

POPBasicAnimation *anim = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];

Custom(自定义)动效可以让设计值创建自定义动效,只需简单处理CADisplayLink,并联系时间-运动关系

在这片简短教程中将不涵盖自定义动效,大家可以看看POP的Github来获取更多进阶知识https://github.com/facebook/pop

步骤4: 给动效添加属性

Pop 让我们可以这样设置动效的属性:

velocity : anim.velocity @(1000.);

fromValue: anim.fromValue @(0.0);

toValue: anim.toValue @(1.0);

bounciness: anim.springBounciness 10;

步骤5 :动起来

若想让物体动起来,只需要添加步骤3所创建的东西到视图。

[self.yourView.layer pop_addAnimation:anim forKey:@"typeANameForYourAnimationHere"];

这就是POP简单创建动效的教程。大家可以看看例子来理解如何创建动效。争取努力变得技艺纯熟吧。

步骤6:测试效果

Pop有相关文件扩展作为测试。安装测试文件的方法是用终端进入POP根目录,然后输入

pod install

必须确保CocoaPods已经安装

# 动效案例

这个动效将按钮缩小到一半

POPSpringAnimation *scaleAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY]; 
scaleAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(0.5, 0.5)]; 
scaleAnimation.springBounciness = 10.f; 
[self.button.layer pop_addAnimation:scaleAnimation forKey:@"scaleAnim"];

这个动效将按钮旋转

POPSpringAnimation *rotationAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerRotation];
rotationAnimation.beginTime = CACurrentMediaTime() + 0.2;
rotationAnimation.toValue = @(1.2); 
rotationAnimation.springBounciness = 10.f; 
rotationAnimation.springSpeed = 3; 
[button.layer pop_addAnimation:rotationAnimation forKey:@”rotationAnim”];

这个改变透明度:

POPBasicAnimation *opacityAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerOpacity];
opacityAnimation.toValue = @(0.5);
[animView.layer pop_addAnimation:opacityAnimation forKey:@"opacityAnimation"];

#更多

Pop Github : https://github.com/facebook/pop

Popping -Pop案例 : https://github.com/schneiderandre/popping

POP使用教程: https://github.com/maxmyers/FacebookPop

中文教程

POP使用指南(来自Cocohina)

使用FaceceBook的Pop框架替换UIScrollView的减速动画(来自Cocohina)

Facebook POP 进阶指南(来自Cocohina)

最新文章

  1. left和offsetLeft
  2. android studio 注释模板
  3. MongoDB—— 读操作 Core MongoDB Operations (CRUD)
  4. A strange lift_BFS
  5. initWithFrame 和 initWithCoder
  6. searchDisplayController 时引起的数组越界
  7. 【UI控件总结】【UIScrollView】深入理解篇UIScrollerView
  8. gulp 初体验
  9. IE浏览器中设为首页
  10. LeetCode_Letter Combinations of a Phone Number
  11. C Looooops(扩展欧几里德)
  12. 在mac os 中安装 autoconf and automake
  13. Linux jdk安装多个版本并进行切换
  14. reduce 方法 (Array) (JavaScript)
  15. Web前端有价值的博客文章汇总
  16. linux中find命令高级用法
  17. Shell脚本命令图片
  18. 改变this指向的三种方法
  19. Java知多少(45)未被捕获的异常
  20. blog决定不用二级域名,改为二级目录

热门文章

  1. 软件-MQ-RabbitMQ:RabbitMQ
  2. 1.开始Springboot 基本配置和helloworld
  3. python生成VOC2007的类库
  4. Tensorflow技巧
  5. YUM配置文件
  6. bzoj 1266 [AHOI2006] 上学路线
  7. java多线程三种方式
  8. Delphi 设计模式:《HeadFirst设计模式》Delphi7代码---命令模式之RemoteControlTest[转]
  9. ie6 png 透明的解决方法,大网站都在用
  10. HTTPS的实现