2011-07-19 3 views
0

スワイプ方向に基づいてラベルを変更するアプリを作成しようとしています。しかし、画面上のどこでもスワイプできるのではなく、特定のビューだけをスワイプしたいと思っています。 .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"; 
} 

答えて

2

をあなたがしたいUIViewに2つのUIGestureRecognizer S(右スワイプと左スワイプのために別のもの)を追加することによって、あなたは後にしているものを達成することができますが、スワイプを受け取る。

AppleのSimpleGestureRecognizer sample projectは、これを設定する方法の素晴らしい説明です。

0

オーガナイザのUIViewオブジェクトに対してuiviewクラスが選択されているかどうかをIDインスペクタで確認します。私はUIViewのサブクラスでtouchesBeganメソッドを実装していると思います。

関連する問題