LPPloveROU 2013-07-05 06:04 采纳率: 50%
浏览 4295
已结题

UIGraphicsBeginImageContext绘制

在视图中画线。而且最好不用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);
}
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 thinkphp6配合social login单点登录问题
    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch