3
我期待有一些標記爲紅色的標記,但不知道它是否可以完成。書法繪圖IOS Coregraphics
它看起來像使用書法筆標記。
試行下面的代碼由「安德烈」作爲回答,我得到的空間下面的輸出,同時繪製。
刷圖像可以在這裏找到使用的是
製作的代碼的進一步變化,我發現還是我沒能得到預期的結果。 這裏我試圖填充當前點和下一點之間存在的路徑。
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGFloat w=5.0;
CGFloat h=2.0;
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
for(int i=0;i<self.positions.count;i++){
CGPoint point=[[self.positions objectAtIndex:i] CGPointValue];
CGFloat x=point.x-(w/2.0);
CGFloat y=point.y-(h/2.0);
CGContextFillRect(context, CGRectMake(x, y, w, h));
if(i+1<self.positions.count){
CGPoint nextPoint=[[self.positions objectAtIndex:(i+1)] CGPointValue];
CGMutablePathRef myPath=CGPathCreateMutable();
CGPathMoveToPoint(myPath, NULL, x, y);
CGFloat x1=nextPoint.x-(w/2.0);
CGFloat y1=nextPoint.y-(h/2.0);
CGPathAddLineToPoint(myPath, NULL, x1, y1);
CGPathAddLineToPoint(myPath, NULL, w, y1);
CGPathAddLineToPoint(myPath, NULL, w, y);
CGPathCloseSubpath(myPath);
CGContextFillPath(context);
}
}
}
從來沒有想過這會很容易畫出來。嘿順便說一句,當我編碼我發現有幾個空位被遺漏,這不應該發生,因爲我們不斷更新touchesMoved: – weber67
@ weber67' touchesMoved'會跳過一些位置。你必須記住最後一個位置並插入它們之間的位置。 – Sulthan
@ weber67你應該使用上面提到的Sulthan的某種內插。正確的邏輯是實現插入的線條繪圖,您可以從觸摸中獲得點。但複雜的數字可能會變慢。 –