我使用ACEDrawingView在視圖內繪製。iOS:圍繞繪製的路徑裁剪?
我怎麼會檢測到圖紙的寬度和高度,這樣我可以裁剪它周圍,像這樣:
更新: @Duncan指出後我在正確的方向,我能夠查看源代碼,發現以下內容:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
// save all the touches in the path
UITouch *touch = [touches anyObject];
previousPoint2 = previousPoint1;
previousPoint1 = [touch previousLocationInView:self];
currentPoint = [touch locationInView:self];
if ([self.currentTool isKindOfClass:[ACEDrawingPenTool class]]) {
CGRect bounds = [(ACEDrawingPenTool*)self.currentTool addPathPreviousPreviousPoint:previousPoint2 withPreviousPoint:previousPoint1 withCurrentPoint:currentPoint];
CGRect drawBox = bounds;
drawBox.origin.x -= self.lineWidth * 2.0;
drawBox.origin.y -= self.lineWidth * 2.0;
drawBox.size.width += self.lineWidth * 4.0;
drawBox.size.height += self.lineWidth * 4.0;
self.drawingBounds = bounds; // I added this property to allow me to extract the bounds and use it in my view controller
[self setNeedsDisplayInRect:drawBox];
}
else if ([self.currentTool isKindOfClass:[ACEDrawingTextTool class]]) {
[self resizeTextViewFrame: currentPoint];
}
else {
[self.currentTool moveFromPoint:previousPoint1 toPoint:currentPoint];
[self setNeedsDisplay];
}
}
但是我得到這個當我測試的範圍:
我會繼續努力弄明白,但如果有人能夠幫助這將是偉大的!
更新3:使用CGContextGetPathBoundingBox我終於能夠實現它了。
謝謝馬特!我實際上找到了一個'CGMutablePathRef path'實例變量,並使用'return CGPathGetBoundingBox(path);'我能夠得到它! – KingPolygon
糟糕,我的方法似乎只得到最新的路徑。所以,如果我繪製多條線(繪製,提起手指和繪製),它只會看到更新的路徑。我會給你的方法去。 – KingPolygon
哦,只需保留所有路徑並製作複合路徑並獲取該路徑的邊界框即可。我的答案是不必要的。你的方式是最好的。 – matt