Reputation: 2288
I have a UIBezierPath:
CGPathRef tapTargetPath = CGPathCreateCopyByStrokingPath(tracePath.CGPath, NULL, marginError, tracePath.lineCapStyle, tracePath.lineJoinStyle, tracePath.miterLimit);
UIBezierPath *tracePath = [UIBezierPath bezierPathWithCGPath:tapTargetPath];
when it is touched in the method:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
I get a point. When i retrieve 2 points i want to get the segment(area or perimeter) of the UIBezierPath that i am touching, how can i accomplish this?
Upvotes: 0
Views: 1215
Reputation: 182
CGPathGetBoundingBox does not take into account the brush size and will cut the borders.
-(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]];
}
Upvotes: 1
Reputation: 3854
Use CGPathGetBoundingBox
to get the bounding box of the path, i.e., the smallest rectangle enclosing all points in the path:
CGRect pathBounds = CGPathGetBoundingBox(tracePath.CGPath)
Upvotes: 0