views:

68

answers:

3

I am working to make my iPhone app compatible for the iPad. The user can tap or swipe the screen to activate certain functions, and it works fine on my iPhone version. There is a UIScrollView on the page which I have subclassed to make it "swipeable," i.e. it passes up all of its touch functions to its superview as such:

 @implementation SwipeableScrollView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];

    [self.superview touchesBegan:touches withEvent:event];

}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesMoved:touches withEvent:event];

    [self.superview touchesMoved:touches withEvent:event];
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesEnded:touches withEvent:event];

    [self.superview touchesEnded:touches withEvent:event];
} 

@end

This works fine on the iPhone version, passing both taps and swipe gestures, but on the iPad, I get the following strange behavior:

  1. Taps are passed to the superview properly.
  2. But, swipe gestures are not passed at all.

Any idea why this would be working on the iPhone but not the iPad?

A: 

While overriding touch events was necessary on the iPhone, for the iPad Apple has introduced UIGestureRecognizers that make tasks like this much more straightforward and easy to implement. You will probably need to refactor your code to use them.

Jason
That still doesn't work in the iPad... now it just doesn't recognize any taps at all. But either way, if it worked on the iPhone, why should it stop working on the iPad?
Jason
Because Apple completely reworked the way touch events are delivered to controls. So you are saying that you have replaced your touch override code with a `UISwipeGestureRecognizer` and it still doesn't work?
Jason
Yes--that is exactly what happened.
Jason
A: 

I'm not entirely sure why this is happening (I guess UIScrollView sort of needs to handle all the touches), but "split"'s solution in this thread helped me solve this issue.

Kalle
A: 

The problem is, that UIScrollView on the iPad cancels content touches very fast, even if canCancelContentTouches is set to NO. Also, overwriting -touchesShouldCancelInContentView: does not help. Read more here: link text

BugAlert