ビューに頻繁に線を引きたいのですが、うまくいきません。以前に描画された線の状態も維持する必要があるため、drawRect を使用したくありません。以下は線画のコードです。ガイドしてください。
- (void)drawPathWithPoints:(int)xAxis andYaxis:(int)yAxis
{
CGSize screenSize = drawingImgView.frame.size;
UIGraphicsBeginImageContext(drawingImgView.frame.size);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
[drawingImgView.image drawInRect:CGRectMake(0, 0, screenSize.width, screenSize.height)];
CGContextSetLineCap(currentContext, kCGLineCapRound);
CGContextSetLineWidth(currentContext, 9.0);
CGContextSetRGBStrokeColor(currentContext, 0, 0, 1, 1);
CGContextBeginPath(currentContext);
CGMutablePathRef pointPath = CGPathCreateMutable();
CGContextMoveToPoint(currentContext,xAxis,yAxis);
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.duration = 3.0;
pathAnimation.delegate = self;
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
CGPathMoveToPoint(pointPath, NULL, xAxis, yAxis);
CGContextAddLineToPoint(currentContext, xAxis, yAxis);
CGPathAddLineToPoint(pointPath, NULL, xAxis, yAxis);
pathAnimation.path = pointPath;
myLayer = [[CAShapeLayer alloc] init];
myLayer.strokeColor = [[UIColor greenColor] CGColor];
myLayer.lineWidth = 11.0;
myLayer.fillColor = nil;
myLayer.lineJoin = kCALineJoinBevel;
myLayer.path = pointPath;
[drawingImgView.layer addSublayer:myLayer];
CGPathRelease(pointPath);
}