2013-11-20 53 views
0

的周長我有一個UIBezierPath:獲取區和UIBezierPath IOS

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

使用CGPathGetBoundingBox獲得路徑的邊界框,即最小矩形路徑封閉所有點:

CGRect pathBounds = CGPathGetBoundingBox(tracePath.CGPath) 
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]]; 
} 
+0

您應該使用'CGRectInset'放大您的初始矩形。 – Martin