Simultaneous gesture recognizers in Iphone SDK

前端 未结 5 1298
灰色年华
灰色年华 2020-11-27 05:25

I need to catch two different swipping gestures using UISwipeGestureRecognizer(for example, UISwipeGestureRecognizerDirectionRight and UISwip

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 05:25

    The answer: "Um, a quick look at the documentation..." from Phoenix absolutely will not work!

    He is setting a mask, then using the same variable to test as if the recognizer cleared it and set a single bit. It stores, as he correctly quoted from the documentation:

    The permitted directions of the swipe

    sender.direction
    

    will simply return the mask you set initially and in his example, will never resolve to a single direction!

    UISwipeGestureRecognizerDirectionRight == 1
    UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft == 3
    

    Additionaly, for most cases you don't need to:

    • setup a delegate
    • permit simultaneous gesture recognition (unless you want simultaneous swipes; not likely)
    • send the recognizer to the selector

    The following works for me:

       UISwipeGestureRecognizer* swipe;
    
       swipe = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeL)] autorelease];
       swipe.direction = UISwipeGestureRecognizerDirectionLeft;
       [view addGestureRecognizer:swipe];
    
       swipe = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeR)] autorelease];
       swipe.direction = UISwipeGestureRecognizerDirectionRight; // default
       [view addGestureRecognizer:swipe];
    

提交回复
热议问题