0

ユーザーがジェスチャ (左右のスワイプ) を実行してタブをフリックできる iPhone アプリを作成しています。私の問題は、一部のページにピッカービュー、Web ビュー、テキストフィールド、ボタンなどのビューがあることです。スワイプはこれらでは機能しません。グローバルなジェスチャーを持つ方法はありますか?

参考までに、私のジェスチャーコードの例:

//Swipe between tabs
#define mindrag 100
CGPoint mystartTouchPosition;
BOOL isProcessingListMove;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    CGPoint newTouchPosition = [touch locationInView:self.view];
    if(mystartTouchPosition.x != newTouchPosition.x || mystartTouchPosition.y != newTouchPosition.y) {
        isProcessingListMove = NO;
    }
    mystartTouchPosition = [touch locationInView:self.view];
    [super touchesBegan:touches withEvent:event];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{
    UITouch *touch = touches.anyObject;
    CGPoint currentTouchPosition = [touch locationInView:self.view];

    // If the swipe tracks correctly.
    double diffx = mystartTouchPosition.x - currentTouchPosition.x + 0.1; // adding 0.1 to avoid division by zero
    double diffy = mystartTouchPosition.y - currentTouchPosition.y + 0.1; // adding 0.1 to avoid division by zero

    if(abs(diffx / diffy) > 2.5 && abs(diffx) > mindrag)
    {
        // It appears to be a swipe.
        if(isProcessingListMove) {
            // ignore move, we're currently processing the swipe
            return;
        }

        if (mystartTouchPosition.x < currentTouchPosition.x) {
            isProcessingListMove = YES;
            self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];
            return;
        }
        else {
            isProcessingListMove = YES;

            self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:3];

            return;
        }
    }
    else if(abs(diffy / diffx) > 1)
    {
        isProcessingListMove = YES;
        [super touchesMoved:touches withEvent:event];
    }
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{
    isProcessingListMove = NO;
    [super touchesEnded:touches withEvent:event];
}
// End of swipe

どんな入力でも大歓迎です。

4

1 に答える 1

1

もちろん、ジェスチャ検出が基礎となるビューにタッチを渡すことができる限り、これらのジェスチャキャプチャビューをサブクラスUIImagePickerController化して追加することができます。UIWebView

于 2010-02-14T08:44:48.153 に答える