我有一个UIBezierPath:
CGPathRef tapTargetPath = CGPathCreateCopyByStrokingPath(tracePath.CGPath, NULL, marginError, tracePath.lineCapStyle, tracePath.lineJoinStyle, tracePath.miterLimit);
UIBezierPath *tracePath = [UIBezierPath bezierPathWithCGPath:tapTargetPath];
在方法中触及时:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
我明白了。当我获取2个点时,我想获得我正在触摸的UIBezierPath的片段(区域或周长),我该如何实现?
答案 0 :(得分:1)
CGPathGetBoundingBox没有考虑画笔大小,会切割边框。
-(CGRect) getBiggerFrameFromPath:(CGPathRef) path{
CGRect tmpFrame = CGPathGetBoundingBox(path);
CGRect biggerFrame = CGRectMake(tmpFrame.origin.x-self.brushSize/2,
tmpFrame.origin.y-self.brushSize/2,
tmpFrame.size.width+self.brushSize,
tmpFrame.size.height+self.brushSize);
return biggerFrame;
}
-(void) refreshDisplayWithPath:(CGPathRef) path{
[self setNeedsDisplayInRect:[self getBiggerFrameFromPath:path]];
}
答案 1 :(得分:0)
使用CGPathGetBoundingBox
获取路径的边界框,即包围路径中所有点的最小矩形:
CGRect pathBounds = CGPathGetBoundingBox(tracePath.CGPath)