我正在使用ACEDrawingView在视图中绘制。
我如何检测绘图的宽度和高度,以便我可以围绕它进行裁剪,如下所示:
更新:在@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我终于能够实现它了。
答案 0 :(得分:1)
我不熟悉AceDrawingView类。我可以告诉你如何使用iOS框架:
将路径创建为UIBezierPath。
询问路径的bounds属性。
答案 1 :(得分:1)