我有下面的代碼,但它不光滑。如果我畫一個圓圈,我會看到尖角。如何在iPhone上用手指滑動/觸摸動作繪製平滑線?
UIGraphicsBeginImageContext(self.view.frame.size);
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(), YES);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
只是一個快速的音符......你可能想取代你UIGraphicsGetCurrentContext與UIGraphicsBeginImageContext之後一個電話呼叫,並將結果存儲在一個變量。沒有必要爲每一行調用UIGraphicsGetCurrentContext,效率低下且難以閱讀。 – v01d 2011-01-23 10:11:58