質問

方法を教えてください行の追加でジェスチャーイベントを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];
}

のです。

役に立ちましたか?

解決

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

(それは画面全体を占有していないため)

しかし、ピッカービューので、あなたがジェスチャーのためにそのビューのコントローラとフィルターでトラップタッチをすることができ、別のビューに表示されなければなりません。

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

他のヒント

できるサブクラスUIPickerView.問題はすで構成するsubviewsるというUIPickerTableることによって、タッチのようなイベント touchesBegan:withEvent: を行います。ったことで傍受されにコード付属のポスト:への対応touchesBeganにUIPickerViewの代わりにUIView

その他の回答/コメントがある。たいと思った空気の澄んではないという非標準(こう)な人に着こちらをご希望のサブクラスUIPickerViewでの最初の行の受け答えが間違っています。

私は一人でそれを残しました。それはあなたが正しい、混乱されていると思います。

ZT>あなたはUIPickerViewをサブクラス化することはできません。 「長いピッカービューのスピンを作るために、私はUIPickerViewをサブクラス化。私のサブクラスは正確に一つの方法だった」<のhref =「http://iphonedevelopment.blogspot.com/2009/01/longer-spinning-blurring.html」からのrel = "nofollowを">長いスピニングとぼかしに。また、 UIPickerViewクラスリファレンスを参照してください。 「UIDatePickerクラスは、日付と時刻を表示するUIPickerViewのカスタムサブクラスを使用しています。」

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top