在Quartz 2D

时间:2015-12-23 10:33:30

标签: ios objective-c canvas quartz-2d

我希望能够在重绘视图时在现有画布上绘制。这怎么可能?

这就是我现在画的方式:

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    // save the current state, as we'll overwrite this
    CGContextSaveGState(context);

    /*
     draw a line across the top of the view
     */
    // move the pen to the starting point
    CGContextMoveToPoint(context, 50, 10);
    // draw a line to another point
    CGContextAddLineToPoint(context, 190, 60);

    /*
     draw a rectangle just below, with a stroke on the outside.
     */
    CGContextAddRect(context, CGRectMake(60, 100, 180, 90));

    /*
     write the previous to the context then
     change the colour to blue and the stroke to 2px.
     */
    CGContextStrokePath(context);
    CGContextSetRGBStrokeColor(context, 1, 1, 1, 1);
    CGContextSetLineWidth(context, 2);

    /*
     draw a circle filling most of the rest of the box.
     */
    CGContextAddEllipseInRect(context, CGRectMake(100, 100, 100, 100));

    // do the actual drawing
    CGContextStrokePath(context);
    // restore the state back after drawing on it.
    CGContextRestoreGState(context);
    }

通缉解决方案伪代码/行为:

- (void)drawRect:(CGRect)rect
{
      Retrieve previously drawn canvas 
       If available then 
            Create new drawings 
            Draw them on top of previous canvas
       If not then
            Create drawings
            Draw them on canvas
            Save canvas so that is available for the next drawRect call
}

0 个答案:

没有答案