Reputation: 112
I've been struggling with a UIScrollView
related problem for about a week now and frankly I can't seem to solve it.
This is that I want to accomplish:
I want the UITableView's
content to slide on top of the LSWeekView
In my first iteration I got everything working by adding the LSWeekView
as a subview to the UITableView
and making it fixed to the top. This worked really well up until some recent changes.
The UITableView
is now wrapped in a UIPageViewController
which makes it possible for the user to swipe from one day to another. The problem that then occurs is that the LSWeekView
is now sliding together with the UITableView
and there're also multiple instances of the LSWeekView
.
What I've tried so far:
A UIView
with an LSWeekView
and a UITableView
(wrapped in UIPageViewController
) as subviews. By using the UITableView's delegate method scrollViewDidScroll
: I was able to adjust the origin the UITableView
. The problem with this solution is that I have to override the contentOffset
of the UITableView so that it doesn't scroll when adjusting the origin. Unfortunently this introduced some problems with the momentum/deceleration of the UITableView
.
A UIScrollView
with an LSWeekView
and a UITableView
(wrapped in UIPageViewController
) as subviews. By subclassing the UITableView and the UIScrollView
I was able to allow simultaneous panning. But again I had to override the contentOffset
so that the UITableView
didn't scroll when panning in the UIScrollView
, so basically the same problem with this solution as well.
Maybe the solutions I've come up with is the way to go and I just have to make them work by applying my own deceleration and such. But I feel like there should be a better way.
Hopefully you guys can help me get back on track with some ideas on how to solve it.
Upvotes: 2
Views: 646
Reputation: 112
I ended up adding the LSWeekView
on top of the UIPageViewController
and then resizing the LSWeekView
when the UITableView
triggered scrollViewDidScroll:
.
layoutSubviews:
self.tableView.contentInset = UIEdgeInsetMake(100, 0, 0, 0);
scrollViewDidScroll:
CGRect frame = self.weekView.frame;
frame.size.height = 100 - scrollView.contentOffset.y;
if (frame.size.height < 0) {
frame.size.height = 0;
}
self.weekView.frame = frame;
Thanks for the help @NavinDev.
Upvotes: 1
Reputation: 995
Here is a simpler approach which worked for me for a similar requirement.
Add the LSWeekView to as a subview to your parent view. Add the table view too as as subview to the the same parentView but above the LSWeekview in hierarchy. Set the tableView's contentInset
[tableView setContentInset:UIEdgeInsetsMake(requiredHeight, 0, 0, 0)];
And set the tableView's backgroundColor to clearColor.
Cheers.
Upvotes: 2