zoukankan      html  css  js  c++  java
  • 用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(0, 0) 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

  • 相关阅读:
    向量
    3D坐标系
    Unity坐标系详解
    5G 系统流程系列:AF 的 Traffic Routing Control 以及 UP 路径管理增强
    Git 合并冲突
    撤销 git commit
    Redis NoSQL
    Netflow/IPFIX 流量收集与分析
    Nokia 5GC 产品概览
    通过 OpenAPI 部署 Npcf_PolicyAuthorization-PostAppSessions API Service
  • 原文地址:https://www.cnblogs.com/Rinpe/p/5167025.html
Copyright © 2011-2022 走看看