UIPanGestureRecognizerを調べる必要があります。
これにより、他のハンドラーに送信されたイベントをキャンセルすることができます。
以前のポイントを保護する方法に関する追加情報で更新されました。
アクションコールバックでは、最初のタッチ位置が通知されますrecognizer.state == UIGestureRecognizerStateBegan
。このポイントをインスタンス変数として保存できます。また、さまざまな間隔でコールバックを受け取りますrecognizer.state == UIGestureRecognizerStateChanged
。この情報を保存することもできます。次に、でコールバックを取得するとrecognizer.state == UIGestureRecognizerStateEnded
、インスタンス変数をリセットします。
- (void)handler:(UIPanGestureRecognizer *)recognizer
{
CGPoint location = [recognizer locationInView:self];
switch (recognizer.state)
{
case UIGestureRecognizerStateBegan:
self.initialLocation = location;
self.lastLocation = location;
break;
case UIGestureRecognizerStateChanged:
// Whatever work you need to do.
// location is the current point.
// self.lastLocation is the location from the previous call.
// self.initialLocation is the location when the touch began.
// NOTE: The last thing to do is set last location for the next time we're called.
self.lastLocation = location;
break;
}
}
お役に立てば幸いです。