2012-05-10 2 views
1

나는 터치 이벤트에 대한 BezierPath를 그리는 중입니다. 이제 제스처 방법을 사용하여 동일한 위치에서 베 지어 경로를 회전해야합니다. 그러나 문제는 회전 후 위치가 바뀌는 것입니다. 그 모습은 다음 이미지와 같습니다. 어떻게 해결할 수 있습니까?BezierPath UIView에서 회전

BezierPath Drawing

어퍼 이미지는 원래의 이미지이다. 는 Apple documentation.

applyTransform:

답변

1

확인이 사전에 나와 함께 아이디어 .. 감사를 공유 지정된 아핀 변환 행렬 사용하여 경로에있는 모든 포인트를 변환합니다.

- (void)applyTransform:(CGAffineTransform)transform 

나는 이것을 시도하지 않았다. 그러나 여기 NSBezierPathrotating-nsbezierpath-objects 링크에서 돌리는 방법이 있습니다. UIBezierPath에서 비슷한 방법을 사용하십시오.

- (NSBezierPath*)rotatedPath:(CGFloat)angle aboutPoint:(NSPoint)cp 
{ 
// return a rotated copy of the receiver. The origin is taken as point <cp> relative to the original path. 
// angle is a value in radians 

if(angle == 0.0) 
    return self; 
else 
{ 
    NSBezierPath* copy = [self copy]; 

    NSAffineTransform* xfm = RotationTransform(angle, cp); 
    [copy transformUsingAffineTransform:xfm]; 

    return [copy autorelease]; 
} 
} 

사용하는 :

NSAffineTransform *RotationTransform(const CGFloat angle, const NSPoint cp) 
{ 
// return a transform that will cause a rotation about the point given at the angle given 

NSAffineTransform* xfm = [NSAffineTransform transform]; 
[xfm translateXBy:cp.x yBy:cp.y]; 
[xfm rotateByRadians:angle]; 
[xfm translateXBy:-cp.x yBy:-cp.y]; 

return xfm; 
}