gpt4 book ai didi

iphone - UIGraphicsBeginImageContext 未绘制

转载 作者:行者123 更新时间:2023-11-29 03:48:00 31 4
gpt4 key购买 nike

我想经常在我的 View 中画线,但它不起作用。我不想使用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);
}

最佳答案

- (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);



CGContextMoveToPoint(currentContext,xAxis,yAxis);

CGContextAddLineToPoint(currentContext, xAxis, yAxis);
CGContextStrokePath(UIGraphicsGetCurrentContext());

drawingImgView.image = UIGraphicsGetImageFromCurrentImageContext();

CGPathRelease(pointPath);
}

关于iphone - UIGraphicsBeginImageContext 未绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17463101/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com