views:

367

answers:

1

I have a UITextView on top of a UIView. They are in a PageScrollView. The user can swipe anyhere outside of the UITextView and flick over the next page (view). I'd like the user to swipe on the UITextView and flick over the next view as well.

The UITextView scrolls vertically when there is to much text, which the user can swipe and see the rest. View paging scrolls horizontally. I need the UITextView to give its horizontal swipe to the UIView. How can I do that?

+1  A: 

If you subclass UITextView and override each of it's touch events:

  • touchesBegan:withEvent:
  • touchesMoved:withEvent:
  • touchesEnded:withEvent:
  • touchesCancelled:withEvent:

with this:

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

This will allow handling of all touches by both the UITextView and its parent view. Since your UITextView scrolls exclusively vertically and your UIScrollView scrolls exclusively horizontally, this will work out fine.

Ed Marty
In touchesBegan, why would this line [touch locationInView: self.view]; give this error, "request for member view is something not a struct or union"? I am inheriting from UITextView.
4thSpace
If I can't detect whether the swipe is vertical, how do I know when to hand off the swipe to the PageScrollView?
4thSpace
UITextView IS a view, it doesn't CONTAIN one. Juse use locationInView:self. As for detecting whether the swipe is vertical or horizontal, you don't need to. Let both views handle both types of swipes, since swiping horizontally has no effect on a UITextView and siping vertically has no effect on a PageScrollView, it won't matter.
Ed Marty
Thanks. Paging works when I swipe over a UITextView but vertically scrolling on the UITextView doesn't work. Any suggestions?
4thSpace
Just to make sure, you are calling [super touchesXXX] as well, right? If you comment out the nextResponder line, that should stop the page scrolling, and if you comment out the super line, it should stop the text view scrolling.
Ed Marty