XMG CAKeyFrameAnimation

用贝泽尔曲线描绘了一个路径。然后让CAKeyFrameAnimation的path是这个。就可以描绘出这个曲线路径了

 CAKeyframeAnimation*keyFrameAnimation=[CAKeyframeAnimation animation];

        

        keyFrameAnimation.keyPath=@"position";

        

        keyFrameAnimation.duration=2;

        //贝泽尔曲线描绘的路径

        keyFrameAnimation.path=_bezierPath.CGPath;

        keyFrameAnimation.repeatCount=MAXFLOAT;

        

        [self.singleImageView.layer addAnimation:keyFrameAnimation forKey:nil];



#import "DrawView.h"


@interface DrawView()


@property (weak, nonatomic) IBOutlet UIImageView *singleImageView;

//@property (weak,nonatomic)UIImageView*imageView;U

@property(nonatomic,strong)UIBezierPath*bezierPath;

@end



@implementation DrawView


/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    // Drawing code

}

*/


-(void)awakeFromNib{

    

    [self addGestureRecognizer:[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panClick:)]];

    

}


-(void)panClick:(UIPanGestureRecognizer*)pan{

    

     CGPoint currentP=[pan locationInView:self];

    if (pan.state==UIGestureRecognizerStateBegan) {

        

       

        _bezierPath=[UIBezierPath bezierPath];

        

        [_bezierPath moveToPoint:currentP];

        

        _bezierPath.lineWidth=5;

        

    }else if(pan.state==UIGestureRecognizerStateChanged){

        

        [_bezierPath addLineToPoint:currentP];

        //每次添加线的时候 画一次

        [self setNeedsDisplay];

        

    }else if(pan.state==UIGestureRecognizerStateEnded){

        

        CAKeyframeAnimation*keyFrameAnimation=[CAKeyframeAnimation animation];

        

        keyFrameAnimation.keyPath=@"position";

        

        keyFrameAnimation.duration=2;

        //贝泽尔曲线描绘的路径

        keyFrameAnimation.path=_bezierPath.CGPath;

        keyFrameAnimation.repeatCount=MAXFLOAT;

        

        [self.singleImageView.layer addAnimation:keyFrameAnimation forKey:nil];

    }

    

//    [self setNeedsDisplay];

    

}


-(void)drawRect:(CGRect)rect

{

    [[UIColor redColor]setStroke];

    [self.bezierPath stroke];

}









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值