views:

2423

answers:

1

Hi,

I have a UIScrollView that contains a UITextView (not editable). I can't make the UIScrollView gets the touch events, UITextView seems to get them and keep them . Any idea how to let UIScrollView gets the touch events?

I want UITextView to still be scrollable vertically (my UIScrollView is scrollable only horizontally).

+3  A: 

In your UITextView subclass, do this:

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

If you want UITextView to handle the touches too, then I believe you can do this:

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

but it might result in really weird behavior.

Can Berk Güder
I'd like to keep scroll enabled in the UITextView. Won't this avoid the UITextView to be scrollable? I updated my question to give more information.
pbernery
It would. So you want the touches to be received by both views?
Can Berk Güder
It works well! And no weird behavior, UIScrollView and UITextView behaves sa expected. Thank you!
pbernery
you're welcome. =)
Can Berk Güder