2011-11-19 44 views
1

我想知道TouchImageView中預定義2點的最終座標。 1.如果我只是移動touchimageview,這些代碼沒問題。 2.但如果我縮放或旋轉touchimageview,ptLeft和ptRight不正確。TouchImageView在iOS中的座標變換


CGPoint ptLeft = CGPointMake (100, 100); 
CGPoint ptRight = CGPointMake (200, 200); 
TouchImageView *touchView = [[TouchImageView alloc] initWithFrame:rect]; 

.... 
.... 

/***** get the coordinate after TouchImageView has been scaled or rotated *****/ 
ptLeft = CGPointApplyAffineTransform(ptLeft, touchView.transform); 
ptRight = CGPointApplyAffineTransform(ptRight, touchView.transform); 

這裏是touchimageview源代碼 - TouchImageView source code

回答

1

我會使用UIView的方法convertPoint:fromView:或convertPoint:toView:。喜歡的東西:

ptLeft = [touchView convertPoint:ptLeft toView:[touchView superview]];

(後者參數應該認爲你想有一點看起來你正在試圖獲得其在上海華,但你可能想使用self.viewnil。或其他的東西)

+0

嗨,傑西,我還有一個問題,你能幫忙嗎?在我的程序中,我定義了一個綁定矩形,CGRect rectBound = CGRectMake(10,10,300,460);現在,如果ptLeft或ptRight移出界限,我想取消touchimageview的移動(或旋轉)。你知道該怎麼做嗎? I – user1055135

+0

也許你可以用更多的細節創建另一個問題?對我來說最直接的解決方案是設置一個BOOL指示它超出界限,並且如果設置了BOOL,則停止旋轉。您可以使用CGRectContainsPoint進行實際測試。 –