0
我想擁有它,所以當它的平底鍋手勢結束時,檢查結束位置是否在某個區域內,在我的情況下一個正方形。我有下面的代碼,它更少的工作,但由於某種原因,即使平底鍋在廣場結束,它是說它不是。潘姿手勢已經結束的位置
-(void)panHandler:(UIPanGestureRecognizer*)recognizer{
CGPoint translation = [recognizer translationInView:self.view];
switch (recognizer.state){
case UIGestureRecognizerStateBegan:
_stickImage.center = CGPointMake(_stickImage.center.x + translation.x, _stickImage.center.y + translation.y);
break;
case UIGestureRecognizerStateChanged:
_stickImage.center = CGPointMake(_stickImage.center.x + translation.x, _stickImage.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
break;
case UIGestureRecognizerStateEnded:
NSLog(@"Ended");
if(translation.x > _rectView.frame.origin.x && translation.x < (_rectView.frame.origin.x + _rectView.frame.size.width)){
if(translation.y > _rectView.frame.origin.y && translation.y < (_rectView.frame.origin.y + _rectView.frame.size.height)){
NSLog(@"In the grid!");
}
}
else{
NSLog(@"out of the grid");
}
break;
default:
break;
}
}
我可以使用翻譯x和y的位置像我一樣?或者我會如何找到平底鍋的位置是否在廣場?任何幫助將非常感謝謝謝!
這解決了這個問題的方法移動,謝謝!我不確定潘是否有這個選擇。 – Cris