zoukankan      html  css  js  c++  java
  • 学习IOS开发UI篇--Quartz2D基本绘图

      Quartz2D绘图的代码步骤

    1.获得图形上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    2.拼接路径(下面代码是搞一条线段)
    CGContextMoveToPoint(ctx, 10, 10);
    CGContextAddLineToPoint(ctx, 100, 100);

    3.绘制路径
    CGContextStrokePath(ctx); // CGContextFillPath(ctx);

      常用拼接路径函数

    1.新建一个起点
    void CGContextMoveToPoint(CGContextRef c, CGFloat x, CGFloat y)

    2.添加新的线段到某个点
    void CGContextAddLineToPoint(CGContextRef c, CGFloat x, CGFloat y)

    3.添加一个矩形
    void CGContextAddRect(CGContextRef c, CGRect rect)

    4.添加一个椭圆
    void CGContextAddEllipseInRect(CGContextRef context, CGRect rect)

    5.添加一个圆弧
    void CGContextAddArc(CGContextRef c, CGFloat x, CGFloat y,
      CGFloat radius, CGFloat startAngle, CGFloat endAngle, int clockwise)

      常用绘制路径函数

    1.Mode参数决定绘制的模式
    void CGContextDrawPath(CGContextRef c, CGPathDrawingMode mode)

    2.绘制空心路径
    void CGContextStrokePath(CGContextRef c)

    3.绘制实心路径
    void CGContextFillPath(CGContextRef c)

    提示:一般以CGContextDraw、CGContextStroke、CGContextFill开头的函数,都是用来绘制路径的

      图形上下文栈的操作

    1.将当前的上下文copy一份,保存到栈顶(那个栈叫做”图形上下文栈”)
    void CGContextSaveGState(CGContextRef c)

    2.替换掉当前的上下文
    void CGContextRestoreGState(CGContextRef c)

    使用CGContextSclateCTM等方法,一定要在赋值属性前调用

    使用CGContextClip时候,一定要在绘制前调用

  • 相关阅读:
    Android动画 interpolator的用法
    ListView的addAll方法
    界面切换动画
    ListView的setSelectionFromTop()方法与setSelection()方法的联系
    new总结
    linux中进程控制
    linux设备模型
    如何将驱动加入内核
    linux缓冲的概念fopen /open,read/write和fread/fwrite区别
    点云的滤波
  • 原文地址:https://www.cnblogs.com/zhaoyan/p/3778943.html
Copyright © 2011-2022 走看看