Reputation: 831
I would like to have a UIScrollView I can interact with (mainly horizontal swipe to display images) BELOW a UITableView.
The idea is to set the UITableView tableHeaderView of the same size than the UIScrollView with a clear backgroundColor and opaque set to NO, and add
[self.view addSubview:self.scrollView belowSubview:self.tableView];
Consequently, the UITableView will progressively cover the image gallery while scrolling - what whould not be the case if I set up directly the UIScrollView as the tableHeaderView or as a section header.
It works (from a visual point of view).
But I cannot interact or swipe on the UIScrollView which is below, everything is intercepted by the tableView. I thought setting clean Color + opaque = NO would do the trick.
Any idea ?
Thanks
Romain
Upvotes: 1
Views: 313
Reputation: 406
So, as I understand it, you want to place the UITableView
on top so its contents appear over the UIScrollView
, but you want the UIScrollView
to receive touch events? As you have it set up, that can't happen because the UITableView
is going to receive all touch events within its boundaries, because it has to have user interaction enabled.
Consider one of the following:
UITableView
so that instead of having a tableHeaderView
, the table view resizes itself based on its scrolling position (you can track this with a UIScrollViewDelegate
), so it covers the UIScrollView
as the table view scrolls.touchesBegan:withEvent:
, etc) in either the UITableView
or the tableHeaderView
so that it manually forwards touches events to the UIScrollView
when appropriate. This is a nasty solution, but it may do the trick.pointInside:withEvent:
inside the UITableView
. This method is what the touch-handling system uses to determine whether a view should accept a touch event initially. If you modify it to reject points where you want touches to be sent to the UIScrollView
, then it will not receive any touches in that area, and they will default to the view below it.Upvotes: 2