スワイプ方向に基づいてラベルを変更するアプリを作成しようとしています。しかし、画面上のどこでもスワイプできるのではなく、特定のビューだけをスワイプしたいと思っています。 .xibファイルの新しいビューを作成し、そのビューをタッチの位置に使用してleftViewという名前を付けましたが、それでも画面全体が使用されます。私はtouchesBeganとtouchesMovedメソッドを使用していますので、私は対角線を使用できます。 ここで私が使用しているコードのビットです:複数のスワイプビュー
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
gestureStartPoint = [touch locationInView:leftView];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:leftView];
CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x);
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y);
if ((deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) && currentPosition.x < gestureStartPoint.x){
label.text = @"Left Horizontal swipe detected";
}
else if((deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance) && currentPosition.x > gestureStartPoint.x){
label.text = @"Right Horizontal swipe detected";
}
else if ((deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) && currentPosition.y < gestureStartPoint.y){
label.text = @"Up Vertical swipe detected";
}
else if ((deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance) && currentPosition.y > gestureStartPoint.y){
label.text = @"Down Vertical swipe detected";
}