Facebook POP 动效引擎

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

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

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

步骤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"];

# 动效案例

弹性动画
- (void)spring{
    POPSpringAnimation* framePOP = [POPSpringAnimation animationWithPropertyNamed:kPOPViewBackgroundColor];
    framePOP.springSpeed = 10.f;
    framePOP.springBounciness = 4.f;
    framePOP.toValue =  [UIColor greenColor];
    [framePOP setCompletionBlock:^(POPAnimation * anim , BOOL finsih) {
        if (finsih) {
            NSLog(@"view.frame = %@",NSStringFromCGRect(view.frame));
        }
    }];
    [view pop_addAnimation:framePOP forKey:@"go"];
}

减缓动画
- (void)Decay{
    POPDecayAnimation* decay = [POPDecayAnimation animationWithPropertyNamed:kPOPViewFrame];
//    decay.toValue = [NSValue valueWithCGRect:CGRectMake(200, 400, 100, 100)];
    decay.velocity = [NSValue valueWithCGRect:CGRectMake(200, 300, 100, 100)];
    [view pop_addAnimation:decay forKey:@"go"];
}

基本动画
-(void)basic{
    POPBasicAnimation* basicAnimation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerCornerRadius];
    basicAnimation.toValue = [NSNumber numberWithFloat:CGRectGetHeight(view.frame)/2.];
    basicAnimation.timingFunction =[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
//    basicAnimation.duration = 3.f;
    [basicAnimation setCompletionBlock:^(POPAnimation * ani, BOOL fin) {
        if (fin) {
            NSLog(@"view.frame = %@",NSStringFromCGRect(view.frame));
//            POPBasicAnimation* newBasic = [POPBasicAnimation easeInEaseOutAnimation];
//            newBasic.property = [POPAnimatableProperty propertyWithName:kPOPLayerCornerRadius];
//            newBasic.toValue = [NSNumber numberWithFloat:0];
//            [view.layer pop_addAnimation:newBasic forKey:@"go"];
        }
    }];

    [view.layer pop_addAnimation:basicAnimation forKey:@"frameChange"];
}


组合动画
-(void)group
{
    view.transform = CGAffineTransformMakeRotation(M_PI_2/3);
    POPBasicAnimation* spring = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerPositionY];
    spring.beginTime = CACurrentMediaTime();
    spring.duration = .4f;
    spring.fromValue = [NSNumber numberWithFloat:-100.f];
    spring.toValue = [NSNumber numberWithFloat:CGRectGetMinY(view.frame) + 80];
    [spring setCompletionBlock:^(POPAnimation * ani, BOOL fin) {
    }];

    POPBasicAnimation* basic = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerRotation];
    basic.beginTime = CACurrentMediaTime();
    basic.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    basic.toValue = [NSNumber numberWithFloat:-M_PI_4];
    basic.duration = .4f;

    POPBasicAnimation* rotation = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerRotation];
    rotation.beginTime = CACurrentMediaTime() + .4f;
    rotation.toValue = [NSNumber numberWithFloat:0.f];
    rotation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    rotation.duration = .25f;

    POPBasicAnimation* donw = [POPBasicAnimation animationWithPropertyNamed:kPOPLayerPositionY];
    donw.beginTime = CACurrentMediaTime() + 0.4f;
    donw.toValue = [NSNumber numberWithFloat:CGRectGetMinY(view.frame)];
    donw.duration = .25f;
    donw.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];

    [view.layer pop_addAnimation:spring forKey:@"spring"];
    [view.layer pop_addAnimation:basic forKey:@"basic"];
    [view.layer pop_addAnimation:donw forKey:@"down"];
    [view.layer pop_addAnimation:rotation forKey:@"rotation"];
}

 

#参考

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)

demo参考链接:https://github.com/jxd001/POPdemo/blob/master/README.md

                       http://codeplease.io/

                       http://tapity.com/tutorial-getting-started-with-pop/

 

转载于:https://www.cnblogs.com/moyazi/p/4724357.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值