ios-贝塞尔曲线
git下载地址:git@github.com:lu459700780/UIBezierPath.git
演示:

#import "ViewController.h"
@interface ViewController () @property (nonatomic,assign)BOOL Plus_Minus;
@property (nonatomic,strong)CAShapeLayer * shapeLayer;
@property (nonatomic,strong)UIBezierPath * trackPath;
@property (nonatomic,strong)CAShapeLayer * trackLayer;
@property (nonatomic,strong)UIBezierPath * progressPath;
@property (nonatomic,strong)CAShapeLayer * progressLayer;
@property (nonatomic,strong)NSTimer * timer;
@property (nonatomic,strong)CAShapeLayer * shapeLayerT;
@property (nonatomic,strong)CAShapeLayer * shapeLayerTM; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; _Plus_Minus = YES; //创建CAShapeLayer
self.shapeLayer = [CAShapeLayer layer];
self.shapeLayer.frame = CGRectMake(, , , );
// self.shapeLayer.position = self.view.center;
self.shapeLayer.fillColor = [UIColor cyanColor].CGColor;//填充颜色为ClearColor //设置线条的宽度和颜色
self.shapeLayer.lineWidth = 1.0f;
self.shapeLayer.strokeColor = [UIColor redColor].CGColor; //创建出圆形贝塞尔曲线
UIBezierPath * circlePath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(, , , )]; //让贝塞尔曲线与CAShapeLayer 产生联系
self.shapeLayer.path = circlePath.CGPath; //一、添加并显示 画一个圆形
// [self.view.layer addSublayer:self.shapeLayer]; /*
Stroke:用笔画的意思
在这里就是起始笔和结束笔的位置
Stroke为1的话就是一整圈,0.5就是半圈,0.25就是1/4圈。以此类推
*/
self.shapeLayer.strokeStart = ;
self.shapeLayer.strokeEnd = 0.75; //二、画两个圆,其中一个圆表示进度
[self createBezierPath:CGRectMake(, , , )]; //三、创建转动的圆
[self circleBezierPath];
//四、通过点画线组成一个五边线
[self fiveAnimation];
//五、画一条虚线
[self createDottedLine];
//六、画一个弧线
[self createCurvedLine];
} -(void)createCurvedLine{ UIBezierPath* aPath = [UIBezierPath bezierPath];
aPath.lineWidth = 5.0;
aPath.lineCapStyle = kCGLineCapRound; //线条拐角
aPath.lineJoinStyle = kCGLineCapRound; //终点处理
[aPath moveToPoint:CGPointMake(, )];
[aPath addQuadCurveToPoint:CGPointMake(, ) controlPoint:CGPointMake(, )]; CAShapeLayer * CurvedLineLayer=[CAShapeLayer layer];
CurvedLineLayer.path=aPath.CGPath;
[self.view.layer addSublayer:CurvedLineLayer]; } -(void)createDottedLine{ CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setBounds:self.view.bounds];
[shapeLayer setPosition:self.view.center];
[shapeLayer setFillColor:[[UIColor clearColor] CGColor]]; // 设置虚线颜色为blackColor
[shapeLayer setStrokeColor:[[UIColor colorWithRed:/255.0 green:/255.0 blue:/255.0 alpha:1.0f] CGColor]]; // 3.0f设置虚线的宽度
[shapeLayer setLineWidth:1.0f];
[shapeLayer setLineJoin:kCALineJoinRound]; // 3=线的宽度 1=每条线的间距
[shapeLayer setLineDashPattern:
[NSArray arrayWithObjects:[NSNumber numberWithInt:],
[NSNumber numberWithInt:],nil]]; // Setup the path
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, , );
CGPathAddLineToPoint(path, NULL, ,); [shapeLayer setPath:path];
CGPathRelease(path); // 可以把self改成任何你想要的UIView, 下图演示就是放到UITableViewCell中的
[[self.view layer] addSublayer:shapeLayer]; } //五角形
-(void)fiveAnimation{ UIBezierPath *aPath = [UIBezierPath bezierPath];
//开始点 从上左下右的点
[aPath moveToPoint:CGPointMake(,)];
//划线点
[aPath addLineToPoint:CGPointMake(, )];
[aPath addLineToPoint:CGPointMake(, )];
[aPath addLineToPoint:CGPointMake(, )];
[aPath addLineToPoint:CGPointMake(, )];
[aPath closePath];
//设置定点是个5*5的小圆形(自己加的)
UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(-/2.0, , , )];
[aPath appendPath:path]; CAShapeLayer *shapelayer = [CAShapeLayer layer];
//设置边框颜色
shapelayer.strokeColor = [[UIColor redColor]CGColor];
//设置填充颜色 如果只要边 可以把里面设置成[UIColor ClearColor]
shapelayer.fillColor = [[UIColor blueColor]CGColor];
//就是这句话在关联彼此(UIBezierPath和CAShapeLayer):
shapelayer.path = aPath.CGPath;
[self.view.layer addSublayer:shapelayer]; } -(void)circleBezierPath{ _timer = [NSTimer scheduledTimerWithTimeInterval:0.15 target:self selector:@selector(circleAnimationTypeOne) userInfo:nil repeats:YES]; self.shapeLayerT = [CAShapeLayer layer];
self.shapeLayerT.frame = CGRectMake(, , , );
self.shapeLayerT.position = self.view.center;
self.shapeLayerT.fillColor = [UIColor clearColor].CGColor; //设置线条的宽度和颜色
self.shapeLayerT.lineWidth = 2.0f;
self.shapeLayerT.strokeColor = [UIColor redColor].CGColor; //设置stroke起始点
self.shapeLayerT.strokeStart = ;
self.shapeLayerT.strokeEnd = ; //创建出圆形贝塞尔曲线
UIBezierPath * circlePath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(, , , )]; //让贝塞尔曲线与CAShapeLayer产生联系
self.shapeLayerT.path = circlePath.CGPath;
//添加并显示
[self.view.layer addSublayer:self.shapeLayerT]; self.shapeLayerTM = [CAShapeLayer layer];
self.shapeLayerTM.frame = CGRectMake(, , , );
self.shapeLayerTM.position = self.view.center;
self.shapeLayerTM.fillColor = [UIColor clearColor].CGColor; //设置线条的宽度和颜色
self.shapeLayerTM.lineWidth = 2.0f;
self.shapeLayerTM.strokeColor = [UIColor blueColor].CGColor; //设置stroke起始点
self.shapeLayerTM.strokeStart = ;
self.shapeLayerTM.strokeEnd = ; //创建出圆形贝塞尔曲线
UIBezierPath * circlePathTM = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(, , , )]; //让贝塞尔曲线与CAShapeLayer产生联系
self.shapeLayerTM.path = circlePathTM.CGPath;
//添加并显示
[self.view.layer addSublayer:self.shapeLayerTM];
} -(void)circleAnimationTypeOne{ NSLog(@"strokeStart===%f",self.shapeLayerT.strokeStart);
NSLog(@"strokeEnd====%f",self.shapeLayerT.strokeEnd); if (self.shapeLayerT.strokeEnd > && self.shapeLayerT.strokeStart < ) { self.shapeLayerT.strokeStart += 0.1;
self.shapeLayerTM.strokeStart += 0.1; }else if(self.shapeLayerT.strokeStart == ){ self.shapeLayerT.strokeEnd += 0.1;
self.shapeLayerTM.strokeEnd += 0.1;
} if (self.shapeLayerT.strokeEnd == ) { self.shapeLayerT.strokeStart = ;
self.shapeLayerTM.strokeStart = ;
}
if (self.shapeLayerT.strokeStart == self.shapeLayerT.strokeEnd) { self.shapeLayerT.strokeEnd = ;
self.shapeLayerTM.strokeEnd = ;
}
} //画两个圆形
-(void)createBezierPath:(CGRect)mybound{ //外圆
_trackPath = [UIBezierPath bezierPathWithArcCenter:self.view.center radius:(mybound.size.width-0.7)/ startAngle: endAngle:M_PI* clockwise:YES];
_trackLayer = [CAShapeLayer new];
[self.view.layer addSublayer:_trackLayer];
_trackLayer.fillColor = nil;
_trackLayer.strokeColor = [UIColor grayColor].CGColor;
_trackLayer.path = _trackPath.CGPath;
_trackLayer.lineWidth = ;
_trackLayer.frame = mybound; //内圆
_progressPath = [UIBezierPath bezierPathWithArcCenter:self.view.center radius:(mybound.size.width-0.7)/ startAngle:-M_PI_2 endAngle:(M_PI*)*0.7 clockwise:YES];
_progressLayer = [CAShapeLayer new];
[self.view.layer addSublayer:_progressLayer];
_progressLayer.fillColor = nil;
_progressLayer.strokeColor = [UIColor redColor].CGColor; _progressLayer.lineCap = kCALineCapRound;
_progressLayer.path = _progressPath.CGPath;
_progressLayer.lineWidth = ;
_progressLayer.frame = mybound; }
@end
ios-贝塞尔曲线的更多相关文章
- iOS贝塞尔曲线(UIBezierPath)的基本使用方法
简介 UIBezierPath是对Core Graphics框架的一个封装,使用UIBezierPath类我们可以画出圆形(弧线)或者多边形(比如:矩形)等形状,所以在画复杂图形的时候会经常用到. 分 ...
- UIBezierPath IOS贝塞尔曲线
//记录 贝塞尔曲线使用 //根据一个矩形画曲线 + (UIBezierPath *)bezierPathWithRect:(CGRect)rect //根据矩形框的内切圆画曲线 + (UIBezi ...
- IOS贝塞尔曲线圆形进度条和加载动画
做项目让做一个加载动画,一个圈圈在转中间加一个图片,网上有好多demo,这里我也自己写了一个,中间的图片可加可不加.其中主要用到贝塞尔曲线.UIBezierPath是对CGContextRef的进一步 ...
- IOS 贝塞尔曲线切割圆角
写一个UIView扩展 1. .h文件 @interface UIView (Corner) - (void)setCornerWithType:(UIRectCorner)type Radius:( ...
- iOS - 贝塞尔曲线,折线,曲线,波浪线
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZHlsYW5fbHdiXw==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...
- iOS开发 贝塞尔曲线
iOS开发 贝塞尔曲线UIBezierPath - 陌云 时间 2014-03-14 11:04:00 博客园-所有随笔区 原文 http://www.cnblogs.com/moyunmo/p/ ...
- iOS - Quartz 2D 贝塞尔曲线
1.贝塞尔曲线 贝塞尔曲线(Bézier curve),又称贝兹曲线或贝济埃曲线,是应用于二维图形应用程序的数学曲线.一般的矢量图形软件通过它来精确画出曲线,贝兹曲线由线段与节点组成,节点是可拖动的支 ...
- iOS 使用贝塞尔曲线绘制路径
使用贝塞尔曲线绘制路径 大多数时候,我们在开发中使用的控件的边框是矩形,或者做一点圆角,是使得矩形的角看起来更加的圆滑. 但是如果我们想要一个不规则的图形怎么办?有人说,叫UI妹子做,不仅省事,还可以 ...
- iOS开发之画图板(贝塞尔曲线)
贝塞尔曲线,听着挺牛气一词,不过下面我们在做画图板的时候就用到贝塞尔绘直线,没用到绘制曲线的功能.如果会点PS的小伙伴会对贝塞尔曲线有更直观的理解.这篇博文的重点不在于如何用使用贝塞尔曲线,而是利用贝 ...
- iOS开发 贝塞尔曲线UIBezierPath
最近项目中需要用到用贝塞尔曲线去绘制路径 ,然后往路径里面填充图片,找到这篇文章挺好,记录下来 自己学习! 转至 http://blog.csdn.net/guo_hongjun1611/articl ...
随机推荐
- Java中域 实例域 静态域
1.java中的域 所谓的域,翻译成英文就是field, 也就是我们常说的字段,或者说是属性. 比如类的字段(属性),局部的,全局的.所谓域,其实是“field”的翻译 然后实例域,就是 实例(&qu ...
- 转:loadrunner ---循环输出关联数组
web_reg_save_param,将Ord参数值设定为ALL,则关联函数将自动把符合条件的关联值保存到参数数组里.在本例中,假设关联值返回三条记录,则LR分别将值保存到sor_1,sor_2,so ...
- Zencart批量删除无图片产品
Zencart批量删除无图片产品 2012-04-23 07:26:18| 分类: 默认分类 |字号 订阅 转自 http://zhongjia33.blog.163.com/blog/#m=0 ...
- apache RewriteCond RewriteRule
http://www.rockbb.com/blog/?p=319 http://www.cnblogs.com/scgw/archive/2011/12/10/2283029.html 我的理解:当 ...
- android脚步---如何看log之程序停止运行,和UI线程和非UI线程之间切换
经常运行eclipse时,烧到手机出现,“停止运行”,这时候得通过logcat查log了.一般这种情况属于FATAL EXCEPTION,所以检索FATAL 或者 EXCEPTION,然后往下看几行 ...
- CentOS 6.5搭建Samba服务器
目标需求:在Windows7下访问CentOS 6.5 root用户桌面/ZS文件夹 0.准备工作 关闭防火墙并开启不起动 service iptables stop chkconfig iptabl ...
- ZOJ3944People Counting<暴力/枚举>
题意:输入一张照片,给出人物的特征,判断有多少个人. .O. /|\ (.) 思路:按照3*3的图统计,只要有一个点符合就加1 #include<cstdio> #include<i ...
- Android PopupWindow的使用技巧(转)
Android PopupWindow的使用技巧 PopupWindow是Android上自定义弹出窗口,使用起来很方便. PopupWindow的构造函数为 public PopupWindow(V ...
- make[1]: *** [/workopenwrt/trunk/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.tools_install_nnnnn] Error 2 make[1]: Leaving directory `/work/openwrt/trunk' make: *** [world]
主要原因是编译时未连上网,编译时需要下载些插件,连接网后,重启下系统再编译下.
- 关于css的伪类和伪元素
现在才发现自己一直没有分清楚css的伪类和伪元素啊,so,总结一下. CSS 伪类用于向某些选择器添加特殊的效果. CSS 伪元素用于将特殊的效果添加到某些选择器. 可以明确两点,第一两者都与选择器相 ...