Note that there are some explanatory texts on larger screens.

plurals
  1. POtouchesBegan doesn't always respond
    primarykey
    data
    text
    <p>I'm detecting a swipe on the screen, and it works exactly the way I want it to. The only thing is, in testing, I keep swiping over and over and over again and at least 90% of the time or more it is responding, but every now and again there is no response.</p> <p>I NSLog'd everything to find the culprit and found that touchesBegan isn't getting detected at all on the few times that this happens.</p> <p>Here's my code, although touchesBegan isn't even getting called so the code shouldn't matter:</p> <pre><code>- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touches began!"); UITouch *touch = [touches anyObject]; CGPoint thisTouch = [touch locationInView:self.view]; touchstartedX = thisTouch.x; touchstartedY = thisTouch.y; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint p = [[touches anyObject] locationInView:self.view]; if ((abs(p.y - touchstartedY)) &lt; 120) { if ((p.x - touchstartedX) &gt; 10) { [self goPrevious]; } else if ((p.x - touchstartedX) &lt; -10) { [self goNext]; } } else { NSLog(@"too much Y"); } } </code></pre> <p>Any ideas?</p> <p>Thanks!</p> <p><em><strong></em>* EDIT WITH SOLUTION <em>*</em></strong> Here's the code I ended up using after exploring UISwipeGestureRecognizer on dredful's suggestion:</p> <p>in .h:</p> <pre><code>UIViewController &lt;UIGestureRecognizerDelegate&gt; UISwipeGestureRecognizer *swipeLeft; UISwipeGestureRecognizer *swipeRight; @property (nonatomic, retain) UISwipeGestureRecognizer *swipeLeft; @property (nonatomic, retain) UISwipeGestureRecognizer *swipeRight; </code></pre> <p>in .m:</p> <pre><code>@synthesize swipeLeft, swipeRight; UIGestureRecognizer *recognizer; recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; self.swipeLeft = (UISwipeGestureRecognizer *)recognizer; swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft; self.swipeLeft = (UISwipeGestureRecognizer *)recognizer; [recognizer release]; recognizer; recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; self.swipeRight = (UISwipeGestureRecognizer *)recognizer; swipeRight.direction = UISwipeGestureRecognizerDirectionRight; self.swipeRight = (UISwipeGestureRecognizer *)recognizer; [recognizer release]; [self.view addGestureRecognizer:swipeLeft]; [self.view addGestureRecognizer:swipeRight]; - (void)handleSwipeFrom:(UISwipeGestureRecognizer *)recognizer { if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft) { [self goNext]; } else { [self goPrevious]; } } - (void)dealloc { [swipeLeft release]; [swipeRight release]; [super dealloc]; } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; self.swipeLeft = nil; self.swipeRight = nil; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload