iPhone - попытка провести линию на CALayer

У меня есть класс UIView, который я использую, чтобы иметь CALayer. Этот слой будет использоваться для рисования линий на основе прикосновения.

Так определяется класс:

- (id)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    if (self == nil) {
        return nil;
    }

    self.layer.backgroundColor = [UIColor redColor].CGColor;
    self.userInteractionEnabled = YES;
    path = CGPathCreateMutable(); 
    return self;
}

тогда у меня есть следующие строки на touchesBegan, TouchesMoved и touchesEnded ...

**touchesBegan**
CGPathMoveToPoint(path, NULL, currentPoint.x, currentPoint.y);
[self.layer setNeedsDisplay];


**touchesMoved**
CGPathAddLineToPoint(path, NULL, currentPoint.x, currentPoint.y);
[self.layer setNeedsDisplay];


**touchesEnded**
CGPathAddLineToPoint(path, NULL, currentPoint.x, currentPoint.y);
[self.layer setNeedsDisplay];

затем у меня есть этот

-(void)drawInContext:(CGContextRef)context {
    CGContextSetStrokeColorWithColor(context, [[UIColor greenColor] CGColor]);
    CGContextSetLineWidth(context, 3.0);
    CGContextBeginPath(context);
    CGContextAddPath(context, path);
    CGContextStrokePath(context);
}

Вызываются методы touchesBegan / Moved / Ended, но этот метод drawInContext никогда не вызывается ...

что мне не хватает ???

спасибо.

0
задан STW 7 August 2013 в 14:13
поделиться