zoukankan      html  css  js  c++  java
  • iOS pop动画之衰减动画的基本使用

    衰减动画

    - (void)viewDidLoad {

        [super viewDidLoad];

        [self initCircleBtn];

    }

    - (void)initCircleBtn {

        // 实例化手势,并最终将手势添加到圆形按钮上

      UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handlePan:)];

        // 实例化圆形按钮

        UIButton *circleBtn = [[UIButton alloc]init];

        circleBtn.bounds = CGRectMake(0, 0, 100, 100);

        circleBtn.center = self.view.center;

        circleBtn.backgroundColor = [UIColor redColor];

        circleBtn.layer.cornerRadius = CGRectGetWidth(circleBtn.frame) / 2;

        [circleBtn addGestureRecognizer:pan];

        [circleBtn addTarget:self action:@selector(handleDown:) forControlEvents:UIControlEventTouchDown];

        [self.view addSubview:circleBtn];

    }

    - (void)handlePan:(UIPanGestureRecognizer *)recognizer {

        CGPoint translation = [recognizer translationInView:self.view];

        recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y);

        [recognizer setTranslation:CGPointMake(0, 0) inView:self.view]; // 这句比较重要,因为handlePan:会持续调用,如果不把上一次调用该方法产生的位移清零,按钮会移动得很快

        // 松手时,启动衰减动画

        if (recognizer.state == UIGestureRecognizerStateEnded) {

            CGPoint velocity = [recognizer velocityInView:self.view]; // 获取松手时,手势在控制器view的速度

            POPDecayAnimation *popAnimation = [POPDecayAnimation animationWithPropertyNamed:kPOPLayerPosition]; // 实例化衰减动画,该衰减动画作用于Position

            [popAnimation setVelocity:[NSValue valueWithCGPoint:velocity]]; // 设置衰减动画的初始速度

            [recognizer.view pop_addAnimation:popAnimation forKey:@"suibian"]; // 添加衰减动画到圆形按钮

        }

    }

  • 相关阅读:
    [TJOI2018]教科书般的亵渎
    luogu P4781 【模板】拉格朗日插值
    [SDOI2010]捉迷藏
    [CQOI2016]K远点对
    BZOJ4066 简单题
    [国家集训队]JZPFAR
    Understanding User and Kernel Mode
    Linux下如何查看系统启动时间和运行时间以及安装时间
    CentOS Linux搭建独立SVN Server全套流程(修改svn仓库地址、服务启动等)
    linux下获取占用CPU资源最多的10个进程,可以使用如下命令组合:
  • 原文地址:https://www.cnblogs.com/oumygade/p/4460796.html
Copyright © 2011-2022 走看看