2013-11-20 3 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