アップルのドキュメントから
スワイプは個別のジェスチャであるため、関連するアクション メッセージはジェスチャごとに 1 回だけ送信されます。
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event
UISwipeGestureRecognizer を使用しても呼び出されません
ユーザーが指を離したことを検出するにはどうすればよいですか?
アップルのドキュメントから
スワイプは個別のジェスチャであるため、関連するアクション メッセージはジェスチャごとに 1 回だけ送信されます。
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event
UISwipeGestureRecognizer を使用しても呼び出されません
ユーザーが指を離したことを検出するにはどうすればよいですか?
UISwipeGestureRecognizer を使用してスワイプを検出する代わりに、イベント処理を使用して自分で検出しました。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
self.initialPosition = [touch locationInView:self.view];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint movingPoint = [touch locationInView:self.view];
CGFloat moveAmt = movingPoint.y - self.initialPosition.y;
if (moveAmt < -(minimum_detect_distance)) {
[self handleSwipeUp];
} else if (moveAmt > minimum_detect_distance) {
[self handleSwipeDown];
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[self reset];
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
[self reset];
}
UIGestureRecognizer をサブクラス化していませんが、必要なビュー コントローラーでのみイベント処理を行いました。reset メソッドでは、ビュー コントローラーに属するいくつかの変数、カウンター、タイマーをリセットしています。
ジェスチャ認識エンジンの状態プロパティを調べる必要があると思います。
- (void)swipe:(UISwipeGestureRecognizer *)recognizer
{
CGPoint point = [recognizer locationInView:[recognizer view]];
if (recognizer.state == UIGestureRecognizerStateBegan)
NSLog(@"Swipe began");
else if (recognizer.state == UIGestureRecognizerStateEnded)
NSLog(@"Swipe ended");
}
scrollView を使用すると、その contentOffset を検出できます
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.contentOffset.y < -100 { // how you needed
// do what you need
}
}