2

タブを変更するためにジェスチャーイベントをuipickerviewに追加するにはどうすればよいですか?カスタムクラスを作成する必要がありますが、uipickerviewの処理方法がわかりません。現在、これを行うためにuiviewsにジェスチャーがありますが、uipickerviewに問題があります。

ビューの私のコード:

#define HORIZ_SWIPE_DRAG_MIN 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) > HORIZ_SWIPE_DRAG_MIN)
    {
        // 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:0];
            return;
        }
        else {
            isProcessingListMove = YES;

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

            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];
}

助けてくれてありがとう。

4

4 に答える 4

2

UIPickerViewをサブクラス化できます。問題は、9つのサブビューで構成されており、そのうちの1つであるUIPickerTableが、touchesBegan:withEvent:必要な行のようなタッチイベントを受信して​​いることです。この投稿の最後に含まれているコードでこれらを正常に傍受することができました: UIViewではなくUIPickerViewでtouchesBeganに応答する

そこにある他の回答/コメントも役に立ちます。私は、(この質問のように)非標準的なことをしている人のためではなく、受け入れられた答えの最初の行が完全に間違っているため、UIPickerViewをサブクラス化することを望んでここに到着した人のために空気をきれいにしたかった。

于 2011-07-06T05:55:48.603 に答える
0

UIPickerViewをサブクラス化することはできません。

ただし、ピッカービューは別のビューに表示する必要があるため(画面全体を占めるわけではないため)、そのビューのコントローラーでタッチをトラップし、ジェスチャをフィルター処理できます。

(私はあなたがやろうとしていることを理解していると仮定します...)タブを変更するためにピッカービューをスワイプすることは非標準のUIであり、おそらくユーザーを混乱させるでしょう。ピッカービューは一種のコントロールとして認識されるため、ピッカーの通常の回転動作のみを期待します。ピッカービューを水平方向にスワイプすることさえ、彼らはどうやって知るのでしょうか?

于 2010-02-16T15:29:02.910 に答える
0

私はそれを放っておいた。それは混乱していたでしょう、あなたは正しいです。

于 2010-02-16T19:09:19.650 に答える
-1

ZT>UIPickerViewをサブクラス化することはできません。「ピッカービューの回転を長くするために、UIPickerViewをサブクラス化しました。私のサブクラスには、Longer SpinningandBlurringのメソッドが1つだけありました」 。UIPickerViewクラスリファレンスも参照してください。「UIDatePickerクラスは、UIPickerViewのカスタムサブクラスを使用して日付と時刻を表示します。」

于 2011-03-14T02:46:34.230 に答える