POPSpringAnimation也许是大多数人使用POP的理由 其提供一个类似弹簧一般的动画效果;实例源代码已经上传至gitHub,地址:https://github.com/wujunyang/facebookPopTest

POPSpringAnimation可配置的属性与默认值为

springBounciness:4.0    //[0-20] 弹力 越大则震动幅度越大

springSpeed     :12.0   //[0-20] 速度 越大则动画结束越快

dynamicsTension :0      //拉力  接下来这三个都跟物理力学模拟相关 数值调整起来也很费时 没事不建议使用哈

dynamicsFriction:0      //摩擦 同上

dynamicsMass    :0      //质量 同上

注意:POPSpringAnimation是没有duration字段的 其动画持续时间由以上几个参数决定

实例1:实现一个X轴运动并有反弹效果的动画,在完成动画后输出当前的坐标值

 //1:初始化第一个视图块
if (self.myRedView==nil) {
self.myRedView=[[UIView alloc]initWithFrame:CGRectMake(, , , )];
self.myRedView.backgroundColor=[UIColor redColor];
[self.view addSubview:self.myRedView];
} //创建一个POPSpringAnimation动画 实现X轴运动 有反弹效果
POPSpringAnimation *anSpring = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionX];
anSpring.toValue =@();
anSpring.beginTime = CACurrentMediaTime() + 1.0f;
anSpring.springBounciness=14.0; //[0-20] 弹力 越大则震动幅度越大
anSpring.springSpeed=12.0; //[0-20] 速度 越大则动画结束越快
[anSpring setCompletionBlock:^(POPAnimation *prop, BOOL fint) {
if (fint) {
NSLog(@"self.myRedView.frame=%@",NSStringFromCGRect(self.myRedView.frame));
}
}];
[self.myRedView pop_addAnimation:anSpring forKey:@"myRedViewposition”];

可以查看到动画结束后,输出的值为:self.myRedView.frame={{285, 80}, {30, 30}}

实例2:实现一个视图块闪动的效果,从0.2到1.0的弹效果 缩放效果

//2:初始化一个视图块

    if (self.myLayView==nil) {

        self.myLayView=[[UIView alloc]initWithFrame:CGRectMake(, , , )];

        self.myLayView.backgroundColor=[UIColor blueColor];

        [self.view addSubview:self.myLayView];

    }

    //创建一个POPSpringAnimation动画 实现闪一下效果 从0.2到1.0的弹效果 缩放效果

    POPSpringAnimation *scaleAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY];

    scaleAnimation.fromValue  = [NSValue valueWithCGSize:CGSizeMake(0.2, 0.2f)];

    scaleAnimation.toValue  = [NSValue valueWithCGSize:CGSizeMake(1.0f, 1.0f)];

    scaleAnimation.beginTime = CACurrentMediaTime() + 1.0f;

    scaleAnimation.springBounciness = 20.0f;

    scaleAnimation.springSpeed = 20.0f;

    [self.myLayView.layer pop_addAnimation:scaleAnimation forKey:@"scaleAnimation”];

实例3:创建一个POPSpringAnimation动画 将视图进行旋转

 //3:初始化一个视图块

    if (self.myRotaView==nil) {

        self.myRotaView=[[UIView alloc]initWithFrame:CGRectMake(, , , )];

        self.myRotaView.backgroundColor=[UIColor yellowColor];

        [self.view addSubview:self.myRotaView];

    }

    //创建一个POPSpringAnimation动画 将视图进行旋转

    POPSpringAnimation *rotationAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerRotation];

    rotationAnimation.beginTime = CACurrentMediaTime() + 0.2;

    rotationAnimation.toValue = @(1.2);

    rotationAnimation.springBounciness = .f;

    rotationAnimation.springSpeed = ;

    [self.myRotaView.layer pop_addAnimation:rotationAnimation forKey:@"rotationAnim”];

实例4:创建一个POPSpringAnimation动画  按键左右摇动

//4:初始化一个按键

    if (self.myButton==nil) {

        self.myButton=[[UIButton alloc]init];

        self.myButton.frame=CGRectMake(, , , );

        self.myButton.backgroundColor = [UIColor grayColor];

        [self.myButton setTitle:@"登录" forState:UIControlStateNormal];

        [self.myButton addTarget:self action:@selector(touchUpInside:) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:self.myButton];

    }

响应事件内容:

-(void)touchUpInside:(id)sender

{

    //创建一个POPSpringAnimation动画  按键左右摇动

    POPSpringAnimation *positionAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerPositionX];

    positionAnimation.velocity = @;

    positionAnimation.springBounciness = ;

    [positionAnimation setCompletionBlock:^(POPAnimation *animation, BOOL finished) {

        self.myButton.userInteractionEnabled = YES;

    }];

    [self.myButton.layer pop_addAnimation:positionAnimation forKey:@"positionAnimation"];

}

实例5:结合先前的POPBasicAnimation动画,制画一个综合的动画效果,就是向下显示一个视图,又可以回收回去;

@interface OtherViewController ()

@property(assign,nonatomic)BOOL isMenuOpen;

@property(strong,nonatomic)UIView *myMenuView;

@property(nonatomic)CGPoint VisiblePosition,HiddenPosition;

@end

@implementation OtherViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    self.view.backgroundColor=[UIColor whiteColor];

    _isMenuOpen=NO;

    self.VisiblePosition=CGPointMake(, );

    self.HiddenPosition=CGPointMake(, -);

    UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:@"显示" style:UIBarButtonItemStylePlain

                                                                     target:self action:@selector(refreshPropertyList)];

    self.navigationItem.rightBarButtonItem = anotherButton;

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

-(void)refreshPropertyList

{

    if (_isMenuOpen) {

        [self hidePopup];

    }

    else

    {

        [self showPopup];

    }

}

//隐藏时响应

- (void)hidePopup

{

    _isMenuOpen = NO;

    POPBasicAnimation *opacityAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerOpacity];

    opacityAnimation.fromValue = @();

    opacityAnimation.toValue = @();

    [self.myMenuView.layer pop_addAnimation:opacityAnimation forKey:@"opacityAnimation"];

    POPBasicAnimation *positionAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerPosition];

    positionAnimation.fromValue = [NSValue valueWithCGPoint:self.VisiblePosition];

    positionAnimation.toValue = [NSValue valueWithCGPoint:self.HiddenPosition];

    [self.myMenuView.layer pop_addAnimation:positionAnimation forKey:@"positionAnimation"];

    POPSpringAnimation *scaleAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY];

    scaleAnimation.fromValue  = [NSValue valueWithCGSize:CGSizeMake(1.0f, 1.0f)];

    scaleAnimation.toValue  = [NSValue valueWithCGSize:CGSizeMake(0.5f, 0.5f)];

    [self.myMenuView.layer pop_addAnimation:scaleAnimation forKey:@"scaleAnimation"];

}

//显示时响应

- (void)showPopup

{

    //初始化视图

    if (self.myMenuView==nil) {

        self.myMenuView=[[UIView alloc]initWithFrame:CGRectMake(,, , )];

        self.myMenuView.backgroundColor=[UIColor redColor];

        [self.view addSubview:self.myMenuView];

    }

    _isMenuOpen = YES;

    POPBasicAnimation *opacityAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerOpacity];

    opacityAnimation.fromValue = @();

    opacityAnimation.toValue = @();

    opacityAnimation.beginTime = CACurrentMediaTime() + 0.1;

    [self.myMenuView.layer pop_addAnimation:opacityAnimation forKey:@"opacityAnimation"];

    POPBasicAnimation *positionAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerPosition];

    positionAnimation.fromValue = [NSValue valueWithCGPoint:self.HiddenPosition];

    positionAnimation.toValue = [NSValue valueWithCGPoint:self.VisiblePosition];

    [self.myMenuView.layer pop_addAnimation:positionAnimation forKey:@"positionAnimation"];

    POPSpringAnimation *scaleAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerScaleXY];

    scaleAnimation.fromValue  = [NSValue valueWithCGSize:CGSizeMake(0.5, 0.5f)];

    scaleAnimation.toValue  = [NSValue valueWithCGSize:CGSizeMake(1.0f, 1.0f)];

    scaleAnimation.springBounciness = 20.0f;

    scaleAnimation.springSpeed = 20.0f;

    [self.myMenuView.layer pop_addAnimation:scaleAnimation forKey:@"scaleAnimation"];

}

@end

最近有个妹子弄的一个关于扩大眼界跟内含的订阅号,每天都会更新一些深度内容,在这里如果你感兴趣也可以关注一下(嘿对美女跟知识感兴趣),当然可以关注后输入:github 会有我的微信号,如果有问题你也可以在那找到我;当然不感兴趣无视此信息;

Facebook开源动画库 POP-POPSpringAnimation运用的更多相关文章

  1. Facebook 开源动画库 pop

    官网:https://github.com/facebook/pop Demo: https://github.com/callmeed/pop-playground 一:pop的基本构成: POPP ...

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

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

  3. Facebook开源动画库 POP-POPBasicAnimation运用

    动画在APP开发过程中还是经常出现,将花几天的时间对Facebook开源动画库 POP进行简单的学习:本文主要针对的是POPBasicAnimation运用:实例源代码已经上传至gitHub,地址:h ...

  4. Facebook开源动画库 POP-小实例

    实例1:图片视图跟着手在屏幕上的点改变大小 - (void)viewDidLoad { [super viewDidLoad]; //添加手势 UIPanGestureRecognizer *gest ...

  5. Facebook开源动画库 POP-POPDecayAnimation运用

    关于POPDecayAnimation的介绍先引用别人写的一些内容,基本上把它的一些注意点都说明了: Decay Animation 就是 POP 提供的另外一个非常特别的动画,他实现了一个衰减的效果 ...

  6. rebound是facebook的开源动画库

    网址:http://www.jcodecraeer.com/a/opensource/2015/0121/2338.html 介绍: rebound是facebook的开源动画库.可以认为这个动画库是 ...

  7. [转] iOS 动画库 Pop 和 Canvas 各自的优势和劣势是什么?

    iOS 动画库 Pop 和 Canvas 各自的优势和劣势是什么? http://www.zhihu.com/question/23654895/answer/25541037 拿 Canvas 来和 ...

  8. 第三方开源动画库EasyAnimation中一个小bug的修复

    看过iOS动画之旅的都知道,其中在最后提到一个作者写的开源动画库EasyAnimation(以下简称EA). EA对CoreAnimation中的view和layer动画做了更高层次的包装和抽象,使得 ...

  9. Lottie安卓开源动画库使用

    碉堡的Lottie Airbnb最近开源了一个名叫Lottie的动画库,它能够同时支持iOS,Android与ReactNative的开发.此消息一出,还在苦于探索自定义控件各种炫酷特效的我,兴奋地就 ...

随机推荐

  1. 如何做好一个ORM框架

    很多人都不太认可以第三方ORM,因为考虑的点不够全面,没有用户群体大的ORM有保证,这点是不可否认确是事实. 但是往往用户群体大的ORM又有不足之处,就拿用户群体最多的两个ORM来说一下吧 1.EF ...

  2. 总结Unity IOC容器通过配置实现类型映射的几种基本使用方法

    网上关于Unity IOC容器使用的方法已很多,但未能做一个总结,故我这里总结一下,方便大家选择. 首先讲一下通过代码来进行类型映射,很简单,代码如下: unityContainer = new Un ...

  3. 【C#】递归搜索指定目录下的指定项目(文件或目录)

    ---------------更新:201411201121--------------- 主要更新说明:将原bool recurse参数改为int depth,这样可以指定递归深度,而不是笼统的是否 ...

  4. 15天玩转redis —— 第五篇 集合对象类型

    这篇我们来看看Redis五大类型中的第四大类型:“集合类型”,集合类型还是蛮有意思的,第一个是因为它算是只使用key的Dictionary简易版, 这样说来的话,它就比Dictionary节省很多内存 ...

  5. 【Java每日一题】20161109

    package Nov2016; import java.lang.reflect.Method; public class Ques1109 { public static void main(St ...

  6. [范例] Firemonkey 弹簧动画

    弹簧动画效果: 不用写任何代码,只需设定下面动画属性: 参考动画曲线: http://monkeystyler.com/guide/Interpolation-and-AnimationType-Il ...

  7. sublime text 开发常用插件

    一.emmet插件 (HTML/CSS代码快速编写插件) 安装步骤:打开Sublime菜单栏>首选项>Package Control> 输入>Package Control: ...

  8. SpringMVC框架介绍

     1. SpringMVC通过一套MVC注解,让POJO成为处理请求的控制器,而无须实现任何接口. 2.支持REST风格的URL请求. 3.采用了松散耦合可插拔组件结构,比其他MVC框架更具扩展性和灵 ...

  9. Struct2

    1.MVC思想概述 Servlet作为前端控制器,负责接收客户端发送的请求,在Servlet中只包含控制逻辑和简单的前端处理:然后调用后端javabean来完成实际的逻辑处理: 最后转发到相应的jsp ...

  10. Mac 连接阿里云服务器

    1. 通过命令行连接 Server 并设置 1.1 连接 Server #: ssh root@hctec.top ssh: 远程连接工具 root: 远程服务器用户名, 此处我用的是: root 用 ...