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 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题