2011-08-09 24 views
0

我有一個UIImageView,我試圖確定何時執行拖動,拖動距離原點的距離。目前,我有這樣的:確定拖動點的距離是多遠

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
UITouch *touch = [touches anyObject]; 
CGPoint location = [touch locationInView:touch.view]; 

if(CGRectContainsPoint(myimage.frame, location) == 0){ 

} 
else 
{ //user didn't tap inside image} 

圖像本身不動,但一個人可以把他們的手指,在圖像上單擊並拖動他們的手指。我只是試圖確定這個距離。

回答

3

如果你想計算距離,如果用戶敲擊你的圖像,你需要記住點(存儲在某處)touchesBegan。 然後在touchesMovedtouchesEnd您將能夠獲得當前點並計算到原點的距離。

如果您需要從UIImageView產地得到的距離,你可以叫[touch locationInView:myImage];

我建議你使用,而不是自行處理觸摸UIGestureRecognizer類。他們更容易實施。