2011-03-07 63 views
0

我繪製了2條直線,但我想旋轉角度的第一條線?在上下文中旋轉一條線?

CGContextBeginPath(context); 
    CGContextSetLineWidth(context, 10.0); 
    CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor); 
    CGContextMoveToPoint(context, 65, 40); 
    CGContextAddLineToPoint(context,165, 40); 
    CGContextStrokePath(context); 
    CGContextClosePath(context); 

    CGContextBeginPath(context); 
    CGContextSetLineWidth(context, 10.0); 
    CGContextSetStrokeColorWithColor(context,[UIColor blackColor].CGColor); 
    CGContextMoveToPoint(context, 85, 80); 
    CGContextAddLineToPoint(context, 185, 80); 
    CGContextStrokePath(context); 
    CGContextClosePath(context); 

回答

1

您應該使用CGAffineTransformMakeRotation。

CGAffineTransform rotation = CGAffineTransformMakeRotation(theAngle); 
    CGContextConcatCTM(context, rotation); 

好運