iOS 动画之购物车 贝塞尔曲线
2016-01-29 10:15
323 查看
//
// 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
// 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
相关文章推荐
- 让iOS程序可以和 iTunes 进行文件交互
- iOS 开发用到的常用工具
- iOS开发笔记--iOS项目中工作空间Workspaces概念的理解
- Launch Screen在iOS7/8中的实现
- IOS 宏与常量的使用
- ios获取设备信息
- 芒果iOS开发之快速注释插件VVDocumenter-Xcode
- 起底多线程同步锁(iOS)
- iOS中POST请求
- iOS :获取通讯录 新的contact框架
- iOS中XML解析
- IOS-MJExtension一句话搞定对象归档(转)
- iOS打电话(有无提示功能)
- iOS去掉导航栏背景图片和底部线
- Mac和iOS开发资源汇总
- Charles --- Mac上的抓包工具 iOS开发
- 漫谈iOS程序的证书和签名机制
- iOS自动打包并发布脚本
- iOS 9 适配系列教程
- JSPatch – 动态更新iOS APP