美文网首页IOS开发
iOS 贝塞尔曲线动画简单实现

iOS 贝塞尔曲线动画简单实现

作者: WTFSSD | 来源:发表于2016-08-17 19:13 被阅读0次
    -(void)quadCurveMove
    {
          UIView * roundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
          roundView.backgroundColor = RandColor;
          [roundView addRadius:10];
          [self.roundViewArray addObject:roundView];
          roundView.x = (self.width - roundView.width)+roundView.width*0.5;;
          roundView.y = (self.height - roundView.height)-roundView.height*0.5;
          [self addSubview:roundView];
          //起始点
          CGPoint startPoint= CGPointMake(roundView.x, roundView.y);
         //结束点
           CGPoint endPoint=     CGPointMake(self.countLabel.x+self.countLabel.width*0.5,    self.countLabel.y+self.countLabel.height*0.5);
        //控制点
          CGPoint controlPoint = CGPointMake(endPoint.x+((startPoint.x-endPoint.x))*0.5, -100);
        
          //绘制贝塞尔曲线
          UIBezierPath * movePath = [UIBezierPath bezierPath];
          [movePath moveToPoint:startPoint];
          [movePath addQuadCurveToPoint:endPoint controlPoint:controlPoint];
        
        //关键帧动画
        CAKeyframeAnimation *keyFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        [keyFrameAnimation setDuration:0.4];
        keyFrameAnimation.path = movePath.CGPath;
        keyFrameAnimation.fillMode = kCAFillModeForwards;
        keyFrameAnimation.removedOnCompletion = NO;
        keyFrameAnimation.delegate = self;
        [roundView.layer addAnimation:keyFrameAnimation forKey:@"movingAnimation"];
    }
    
    //动画结束调用该方法
    -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
        self.count+=1;
        self.countLabel.text=[NSString stringWithFormat:@"%ld",self.count];
        [self.roundViewArray.firstObject removeFromSuperview];
        [self.roundViewArray removeObjectAtIndex:0];
    }       
    
    

    相关文章

      网友评论

        本文标题:iOS 贝塞尔曲线动画简单实现

        本文链接:https://www.haomeiwen.com/subject/cinmsttx.html