IOS Quarzt2D 手动的释放

 

- (void)drawRect:(CGRect)rect
{
    // 1.获取上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    
    // 2.绘制图形
    /*
    // 设置起点
    CGContextMoveToPoint(ctx, 10, 10);
    // 设置终点
    CGContextAddLineToPoint(ctx, 100, 100);
    
    // 3.画圆
    CGContextAddEllipseInRect(ctx, CGRectMake(50, 50, 50, 50));
    */
    
   
    // 2.创建路径(一个path就代表一条路径)
    // 但凡通过quarzt2d中的带有create/ copy / retain 方法创建出来的值都必须手动的释放
    CGMutablePathRef path = CGPathCreateMutable();
    // 设置起点
    CGPathMoveToPoint(path, NULL, 10, 10);
    // 设置终点
    CGPathAddLineToPoint(path, NULL, 100, 100);
    // 将路径添加到上下文中
    CGContextAddPath(ctx, path);
    
    // 3.再创建一条路径用于保存圆
     CGMutablePathRef path2 = CGPathCreateMutable();
    // 在path中添加画的路径
    CGPathAddEllipseInRect(path2, NULL, CGRectMake(50, 50, 50, 50));
    CGContextAddPath(ctx, path2);
    
    // 3.渲染'
    CGContextStrokePath(ctx);
    
    
    // 释放前面创建的两条路径
    CGPathRelease(path);
    CGPathRelease(path2);
    
    // 下面这种方式也可以释放路径
    
//    CFRelease(path);
//    CFRelease(path2);
}

 

posted on 2017-03-21 22:17  守望星空  阅读(103)  评论(0编辑  收藏  举报

导航