Josh Hinman
Josh Hinman

Reputation: 6805

Why doesn't my nested UITableView bounce properly?

I have a UITableView whose cells contain UITableViews that are rotated 90° (so they scroll side-to-side), similar to what is explained here:

http://marcanton.io/blog/nested-orthogonal-tableviews/

When I scroll one of the cells to the end (e.g. all the way to the left or right edge of the content) it bounces as expected. But if it's already at the end and I try to scroll beyond the end of the content (e.g. it's scrolled all the way to the right and I try to scroll further to the right), it doesn't bounce at all, and sometimes erroneously interpretes the scroll attempt as a tap.

The same thing happens if I create a UIScrollView that contains another UIScrollView that is rotated by 90°, so it appears to be an issue with nested scroll views, not table views specifically.

I tried subclassing UITableView and overriding all the UIGestureRecognizerDelegate methods like so:

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return YES;
}

But that has no effect (other than allowing simultaneous horizontal and vertical scrolling, which I don't need).

Upvotes: 1

Views: 606

Answers (2)

Willster
Willster

Reputation: 2586

I found that wrapping the rotated UITableView within a UIScrollView fixed the problem (not sure why this didn't work for you).

Upvotes: 0

Josh Hinman
Josh Hinman

Reputation: 6805

It has everything to do with the fact that the inner table views are rotated by 90 degrees. The observed behavior with the bouncing (and lack thereof) is entirely consistent with a nested scroll view that scrolls along the same axis as its superview.

In the UI, the inner and outer table views appear to scroll along different axes, but behind-the-scenes, due to the rotation transform, they are both scrolling along their own respective y-axis. So the system treats them as if they are scrolling along the same axis.

Upvotes: 1

Related Questions