iOS 动画之购物车 贝塞尔曲线

//

//  ViewController.m

//  test_shapeLayer_01

//

//  Created by admin on 1/28/16.

//  Copyright © 2016 jeffasd. All rights reserved.

//


#import "ViewController.h"


#define pi 3.14159265359

#define   DEGREES_TO_RADIANS(degrees)  ((pi * degrees)/ 180)


@interface ViewController ()


@property(nonatomic, strong) CAShapeLayer *shapeLayer;


@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];


    self.shapeLayer = [CAShapeLayer layer];

//    _shapeLayer.frame = CGRectMake(0, 0, 200, 200);

    _shapeLayer.frame = self.view.frame;

//    _shapeLayer.position = self.view.center;

    _shapeLayer.fillColor = [UIColor clearColor].CGColor;

    

    _shapeLayer.lineWidth = 1.0f;

    _shapeLayer.strokeColor = [UIColor cyanColor].CGColor;

    

//    UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 200, 200)];

    

//    UIBezierPath *circlePath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 200, 200)];

    

    

//    UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150)

//                                                         radius:75

//                                                     startAngle:0

//                                                       endAngle:DEGREES_TO_RADIANS(135)

//                                                      clockwise:YES];

    

//    //绘制二次贝塞尔曲线

//    UIBezierPath *circlePath = [UIBezierPath bezierPath];

    [circlePath moveToPoint:CGPointMake(20, 100)];

//    [circlePath moveToPoint:CGPointMake(0, 100)];

//    [circlePath addQuadCurveToPoint:CGPointMake(200, 100) controlPoint:CGPointMake(100, 0)];

    

    

#if 0

    //绘制三次贝塞尔曲线

    UIBezierPath *circlePath = [UIBezierPath bezierPath];

    [circlePath moveToPoint:CGPointMake(20, 50)];

    [circlePath addCurveToPoint:CGPointMake(200, 50) controlPoint1:CGPointMake(110, 0) controlPoint2:CGPointMake(110, 100)];

    _shapeLayer.path = circlePath.CGPath;

#endif

    

    

    //绘制三次贝塞尔曲线

    UIBezierPath *circlePath = [UIBezierPath bezierPath];

    [circlePath moveToPoint:CGPointMake(20, 100)];

    [circlePath addCurveToPoint:CGPointMake(350, 600) controlPoint1:CGPointMake(110, 0) controlPoint2:CGPointMake(110, 100)];

    _shapeLayer.path = circlePath.CGPath;

    

    

    _shapeLayer.strokeStart = 0;

    _shapeLayer.strokeEnd = 1.0;

    

    [self.view.layer addSublayer:_shapeLayer];

    

    

    CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"position"];

    animation.duration = 3;

    animation.timingFunction = [CAMediaTimingFunction functionWithName:@"easeInEaseOut"];

    animation.repeatCount = 1;

    animation.path = circlePath.CGPath;

    

    UIView *subView = [[UIView alloc] initWithFrame:CGRectMake(100, 20, 10, 10)];

    

//    subView.center = self.view.center;

    

    subView.backgroundColor = [UIColor redColor];

    [self.view addSubview:subView];

    

//    subView.center = self.view.center;

    

    //subView视图添加动画

    [subView.layer addAnimation:animation forKey:@"test"];

    

    

//    //绘制曲线

//    CGContextMoveToPoint(context, 20, 100);//移动到起始位置

//    /*绘制二次贝塞尔曲线

//     c:图形上下文

//     cpx:控制点x坐标

//     cpy:控制点y坐标

//     x:结束点x坐标

//     y:结束点y坐标

//     */

//    CGContextAddQuadCurveToPoint(context, 160, 0, 300, 100);

//    

//    CGContextMoveToPoint(context, 20, 500);

//    /*绘制三次贝塞尔曲线

//     c:图形上下文

//     cp1x:第一个控制点x坐标

//     cp1y:第一个控制点y坐标

//     cp2x:第二个控制点x坐标

//     cp2y:第二个控制点y坐标

//     x:结束点x坐标

//     y:结束点y坐标

//     */

//    CGContextAddCurveToPoint(context, 80, 300, 240, 500, 300, 300);

//    

//    //设置图形上下文属性

//    [[UIColor yellowColor]setFill];

//    [[UIColor redColor]setStroke];

//    

//    

//    //绘制路径

//    CGContextDrawPath(context, kCGPathFillStroke);

    

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值