У меня есть класс 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 никогда не вызывается ...
что такоеМне не хватает ???
спасибо.