0

新しいアプリを開発していて、多くのアプリで頻繁に使用される機能を実装する必要があります。「次のページ」/「前のページ」の機能を、「次のページ」の場合は左から右に、もう一方の場合は右から左に、それぞれスライド ジェスチャで実装したいと考えています。GestureRecognizer について役立つ情報を見たことがありますが、残念ながら私は 3.1.2 ファームウェア バージョンで開発を行っており、まだサポートされていません。チュートリアルとの提案やリンクはありますか?

ありがとうございました

4

2 に答える 2

1

私のコードを見てください:

UISwipeGestureRecognizer * swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(myFunction)];
[swipeRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[view addGestureRecognizer:[swipeRecognizer autorelease]];

スワイプなどの方向を変えることができます;-)

編集:ああ、質問の終わりがわかりませんでした:pしたがって、UIViewを実装し、touchesBeginとtouchesEndを検出し、CGPointの開始と終了を保存して、スワイプかnopかを判断する必要があります;)

于 2010-09-22T08:15:34.463 に答える
0

いくつかのコードであなたの質問に答えるために、これはこのスレッドで与えられた素晴らしい例の私のバージョンです。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = touches.anyObject;
    //Define "CGPoint startTouchPosition;" in  your header
    startTouchPosition = [touch locationInView:self];
    [super touchesBegan:touches withEvent:event];
}

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

    // If the swipe tracks correctly.
   double diffx = startTouchPosition.x - currentTouchPosition.x + 0.1;
   double diffy = startTouchPosition.y - currentTouchPosition.y + 0.1;

   //If the finger moved far enough: swipe
    if(abs(diffx / diffy) > 1 && abs(diffx) > 100)
    {
       if (!swipeHandled) {
        [self respondToSwipe];

        //Define "bool swipeHandled;" in your header
        swipeHandled = true;
       }
    }

   [super touchesMoved:touches  withEvent:event];
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    swipeHandled = true;
    [super touchesEnded:touches withEvent:event];   
}
于 2010-09-22T09:42:02.207 に答える