2019独角兽企业重金招聘Python工程师标准>>>

UIBezierPath基础

UIBezierPath对象是CGPathRef数据类型的封装。每一个直线段或者曲线段的结束的地方是下一个的开始的地方。每一个连接的直线或者曲线段的集合成为subpath。一个UIBezierPath对象定义一个完整的路径包括一个或者多个subpaths。

创建和使用一个path对象的过程是分开的。创建path是第一步,包含一下步骤:

(1)创建一个Bezier path对象。

(2)使用方法moveToPoint:去设置初始线段的起点。

(3)添加line或者curve去定义一个或者多个subpaths。

(4)改变UIBezierPath对象跟绘图相关的属性。

UIBezierPath 代码示例:

- (void)drawRect:(CGRect)rect {#pragma mark - 1. 画一个红色五角形// 创建bezierPath对象UIBezierPath *aPath = [UIBezierPath bezierPath];// 设置颜色[[UIColor redColor] set];// 定义线条宽度aPath.lineWidth = 3;/** stroke时候线条终点的效果** kCGLineCapButt,* kCGLineCapRound,* kCGLineCapSquare*/aPath.lineCapStyle = kCGLineCapRound;/** stroke时候线条连接处的效果** kCGLineJoinMiter,* kCGLineJoinRound,* kCGLineJoinBevel*/aPath.lineJoinStyle = kCGLineJoinMiter;// 设置形状的起点[aPath moveToPoint:CGPointMake(100, 10)];// 画四条线[aPath addLineToPoint:CGPointMake(200.0, 50.0)];[aPath addLineToPoint:CGPointMake(160, 150)];[aPath addLineToPoint:CGPointMake(40.0, 150)];[aPath addLineToPoint:CGPointMake(10.0, 50.0)];// 第五条线通过 closePath 得到[aPath closePath];// 根据坐标将线画出来[aPath stroke];[[UIColor yellowColor] set];[aPath fill];#pragma mark - 2. 创建矩形UIBezierPath *aPath2 = [UIBezierPath bezierPathWithRect:CGRectMake(10, 160, 100, 30)];aPath2.lineWidth = 2;aPath2.lineCapStyle = kCGLineCapRound;aPath2.lineJoinStyle = kCGLineJoinRound;[[UIColor blackColor] set];[aPath2 stroke];[aPath2 removeAllPoints];aPath2 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(120, 160, 100, 30) cornerRadius:5];[aPath2 stroke];#pragma mark - 3. 创建圆形或者椭圆形/** 使用如下方法创建内切圆或者内切椭圆* + (UIBezierPath *)bezierPathWithOvalInRect:(CGRect)rect  * 当传入的rect是一个正方形时,绘制的图像是一个内切圆;当传入的rect是一个长方形时,绘制的图像是一个内切椭圆。*/UIBezierPath *aPath3 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(10, 200, 100, 100)];[aPath3 moveToPoint:CGPointMake(60, 250)];[aPath3 stroke];[aPath3 removeAllPoints];[aPath3 addArcWithCenter:CGPointMake(60, 250) radius:4 startAngle:0 endAngle:M_PI*2 clockwise:YES];[aPath3 fill];#pragma mark - 4. 使用UIBezierPath创建一段弧线// 参数 closewise: 顺时针方向UIBezierPath *aPath4 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(60, 250) radius:70 startAngle:M_PI_4 endAngle:M_PI_4+M_PI_2 clockwise:YES];aPath4.lineWidth = 3;[aPath4 stroke];#pragma mark - 5. 绘制 二次/三次 贝塞尔曲线UIBezierPath *aPath5 = [UIBezierPath bezierPath];[aPath5 moveToPoint:CGPointMake(10, 330)];[aPath5 addQuadCurveToPoint:CGPointMake(130, 330) controlPoint:CGPointMake(10, 400)];// 三次贝塞尔曲线[[UIColor redColor] set];[aPath5 addCurveToPoint:CGPointMake(320, 330) controlPoint1:CGPointMake(140, 400) controlPoint2:CGPointMake(320, 100)];[aPath5 stroke];/// 让控件在 path上面移动的效果. ****************************************CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];moveAnim.path = aPath5.CGPath;moveAnim.removedOnCompletion = YES;[self.imageView.layer addAnimation:moveAnim forKey:nil];#pragma mark - 6. 将文字和图片画在画布上去.//将文字画在画布上[@"Walden" drawAtPoint:CGPointMake(10, 10) withAttributes:nil];UIImage *image = [UIImage imageNamed:@"image1.png"];[image drawInRect:CGRectMake(10, 400, 100, 100)];}

转载于:https://my.oschina.net/whforever/blog/700375

iOS开发 贝塞尔曲线UIBezierPath相关推荐

  1. iOS开发 贝塞尔曲线UIBezierPath(后记)

    使用CAShapeLayer与UIBezierPath可以实现不在view的drawRect方法中就画出一些想要的图形 . 1:UIBezierPath: UIBezierPath是在 UIKit 中 ...

  2. ios 贝塞尔曲线 颜色填充_iOS,贝塞尔曲线(UIBezierPath)

    UIBezierPath简介 使用UIBezierPath类可以创建基于矢量的路径,这个类在UIKit中.此类是Core Graphics框架关于path的一个封装, UIBezierPath对象是C ...

  3. 贝塞尔曲线UIBezierPath简单使用

    //常用属性 /* 1.CGPath: 将UIBezierPath类转换成CGPath 2.currentPoint: 当前path的位置,可以理解为path的终点 3.lineWidth: 线条宽度 ...

  4. Android开发——贝塞尔曲线解析

    相信很多同学都知道"贝塞尔曲线"这个词,我们在很多地方都能经常看到.利用"贝塞尔曲线"可以做出很多好看的UI效果,本篇博客就让我们一起学习"贝塞尔曲线 ...

  5. IOS开发-画曲线画弧线画圆

    (1)导入QuartzCore框架 (2)自定义一个view,然后输入下面的代码: - (void)drawRect:(CGRect)rect {[self drawArc1]; }/*** 曲线*/ ...

  6. matlab 贝塞尔曲线,matlab实现贝塞尔曲线绘图pdf查看

    贝塞尔曲线绘图方法: %Program 3.7 Freehand Draw Program Using Bezier Splines %Click in Matlab figure window to ...

  7. ios 贝塞尔曲线 颜色填充_iOS贝塞尔曲线(UIBezierPath)的基本使用方法

    简介 UIBezierPath是对Core Graphics框架的一个封装,使用UIBezierPath类我们可以画出圆形(弧线)或者多边形(比如:矩形)等形状,所以在画复杂图形的时候会经常用到. 分 ...

  8. ios 贝塞尔曲线 颜色填充_iOS UIBezierPath贝赛尔曲线详解

    UIBezierPath是在画图,定制动画轨迹中都有应用. UIBezierPath主要用来绘制矢量图形,它是基于Core Graphics对CGPathRef数据类型和path绘图属性的一个封装,所 ...

  9. 通过UIBezierPath贝塞尔曲线画圆形、椭圆、矩形

    /**创建椭圆形的贝塞尔曲线*/UIBezierPath *_ovalPath=[UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, 200, ...

最新文章

  1. 第7章——狄克特斯拉算法
  2. python做电脑软件-程序员带你十天快速入门Python,玩转电脑软件开发(二)
  3. MongoDB 权限
  4. 瓦力机器人故障维修_大眼萌!5G巡逻机器人亮相乌镇,24小时值守互联网大会...
  5. Isilon三款新品构建数据湖2.0策略
  6. VS Code Pettier设置换行最大宽度
  7. 高翔orbslam_高翔博士分享ORBSLAM2_with_pointcloud_map的安装步骤
  8. 基于.net开发chrome核心浏览器【五】
  9. python获取灰度图边界
  10. 获取国家全部行政区(名称,简称,区划代码)
  11. Excel如何快速录入甲乙丙丁序列
  12. LeetCode第82场双周赛
  13. css选择器所有后代,CSS 后代选择器
  14. 最系统的网站优化推广大全
  15. 【pandas】 DataFrame缺失值的查找与填充
  16. 麻雀优化算法 优化XGBoost的参数 python代码
  17. GIT切换分支的简单操作
  18. P3392 涂国旗——暴力枚举
  19. 魔百和E900V22C_905L3A(B)_5621DS-安卓9.0-纯净语音
  20. Unity-Rigidbody【刚体】组件-Rigidbody.AddForce的ForceMode 力的模式

热门文章

  1. 第二章 GuassDB 数据库基础知识
  2. safari浏览器横屏怎么设置_Safari浏览器的几个小技巧你掌握了吗?
  3. arduino上传项目出错_Arduino入门前你该知道的事儿
  4. python英语字典程序修改_详解如何修改python中字典的键和值
  5. Java设计模式:设计模式基础知识和原则
  6. [SIGMOD 10] Pregel 基于BSP的大规模图处理系统 学习总结
  7. Apache Flink 简介和编程模型
  8. 项目管理project甘特图模板_【八大项目管理应用】必用项目管理工具对比推荐...
  9. 第七章 前端开发——前端工程化(NPM、脚手架、前端环境搭建)
  10. 使用Pycharm创建一个Django项目