Facebook 开源动画库 pop

一:pop的基本构成:

  • POPPropertyAnimation 属性动画

  • POPSpringAnimation 弹簧效果动画

  • POPBasicAnimation 基于动画

  • POPDecayAnimation 延迟衰减动画

  • POPCustomAnimation 自定义动画

二:其中属性动画的类型:

复制代码
#pragma mark - Static

NSString * const kPOPLayerBackgroundColor = @"backgroundColor";
NSString * const kPOPLayerBounds = @"bounds";
NSString * const kPOPLayerOpacity = @"opacity";
NSString * const kPOPLayerPosition = @"position";
NSString * const kPOPLayerPositionX = @"positionX";
NSString * const kPOPLayerPositionY = @"positionY";
NSString * const kPOPLayerRotation = @"rotation";
NSString * const kPOPLayerRotationX = @"rotationX";
NSString * const kPOPLayerRotationY = @"rotationY";
NSString * const kPOPLayerScaleX = @"scaleX";
NSString * const kPOPLayerScaleXY = @"scaleXY";
NSString * const kPOPLayerScaleY = @"scaleY";
NSString * const kPOPLayerSize = @"size";
NSString * const kPOPLayerSubscaleXY = @"subscaleXY";
NSString * const kPOPLayerSubtranslationX = @"subtranslationX";
NSString * const kPOPLayerSubtranslationXY = @"subtranslationXY";
NSString * const kPOPLayerSubtranslationY = @"subtranslationY";
NSString * const kPOPLayerSubtranslationZ = @"subtranslationZ";
NSString * const kPOPLayerTranslationX = @"translationX";
NSString * const kPOPLayerTranslationXY = @"translationXY";
NSString * const kPOPLayerTranslationY = @"translationY";
NSString * const kPOPLayerTranslationZ = @"translationZ";
NSString * const kPOPLayerZPosition = @"zPosition";

NSString * const kPOPViewAlpha = @"view.alpha";
NSString * const kPOPViewBackgroundColor = @"view.backgroundColor";
NSString * const kPOPViewBounds = kPOPLayerBounds;
NSString * const kPOPViewCenter = @"view.center";
NSString * const kPOPViewFrame = @"view.frame";
NSString * const kPOPViewScaleX = @"view.scaleX";
NSString * const kPOPViewScaleXY = @"view.scaleXY";
NSString * const kPOPViewScaleY = @"view.scaleY";
NSString * const kPOPViewSize = kPOPLayerSize;

NSString * const kPOPTableViewContentOffset = @"tableView.contentOffset";
NSString * const kPOPTableViewContentSize = @"tableView.contentSize";
复制代码

使用:

    POPSpringAnimation *springAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerSize];

三:

示例1:演示图片放大效果动画

复制代码
@interface PPPictureConstraintViewController ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *widthConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightConstraint;

@end

@implementation PPPictureConstraintViewController

- (void)performFullScreenAnimation
{
    //先去除所有的动画
    [self.widthConstraint pop_removeAllAnimations];
    [self.heightConstraint pop_removeAllAnimations];
    
    //创建弹簧动画1
    POPSpringAnimation *heightAnimation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayoutConstraintConstant];
    heightAnimation.springBounciness = 8;
    
    //创建弹簧动画2
    POPSpringAnimation *animation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayoutConstraintConstant];
    animation.springBounciness = 8;
    
    if (!_isInFullscreen)
    {
        animation.toValue = @(320.);
        heightAnimation.toValue = @(208.);
    }
    else
    {
        animation.toValue = @(182.);
        heightAnimation.toValue = @(118.);
    }
    
    //加载动画
    [self.heightConstraint pop_addAnimation:heightAnimation forKey:@"fullscreen"];
    [self.widthConstraint pop_addAnimation:animation forKey:@"fullscreen"];
    
}

@end
复制代码

示例2:创建一个旋转及点击放大 + 号 动画

复制代码
- (IBAction)bigBounceButtonWasPressed:(UIButton *)sender
{
    _buttonToggle = !_buttonToggle;
    
    CALayer *layer = sender.layer;
    
    [layer pop_removeAllAnimations];
    POPSpringAnimation  *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerSize];
    POPSpringAnimation *rotation = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerRotation];

    if (_buttonToggle)
    {
        anim.toValue = [NSValue valueWithCGSize:CGSizeMake(44, 44)];
        rotation.toValue = @(M_PI_4);
        sender.tintColor = [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0];
    }
    else
    {
        anim.toValue = [NSValue valueWithCGSize:CGSizeMake(34, 34)];
        rotation.toValue = @(0);
        sender.tintColor = [UIColor redColor];
    }
    
    anim.springBounciness = 20;
    anim.springSpeed = 16;
    
    anim.completionBlock = ^(POPAnimation *anim, BOOL finished) {
        NSLog(@"Animation has completed.");
    };
    [layer pop_addAnimation:anim forKey:@"size"];
    [layer pop_addAnimation:rotation forKey:@"rotation"];
}
复制代码

 

四:参考:

 

posted @   cocoajin  阅读(2345)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示