pull to refresh
Closed this issue · 3 comments
Hi
I have a pager view that contains 4 tableview, in a main class that inherits from mxsegment i have a header and tableview...when I scroll down , this func called segmentedPager(_ segmentedPager: MXSegmentedPager, didScrollWith parallaxHeader: MXParallaxHeader) ...but I have know idea how to pull to refresh or reload my tableview data..i really take a look at other closed issues but i don't understand anything...especially the proogressviw library you've offered
thanks in advance
any update for this issue?
I have a workaround for adding UIRefreshControl, not an elegant way but it works fine for me.
First I find the MXScrollView
and add UIRefreshControl
to it. This refresh control will be placed under your parallax view, so I moved its Z position to top and move its frame to be on top of the view.
segmentedPager.subviews.forEach { (view) in
if let scrollView = view as? UIScrollView {
contentScrollView = scrollView
contentScrollView?.addSubview(refreshControl)
contentScrollView?.refreshControl = refreshControl
contentScrollView?.scrollsToTop = false
refreshControl.addTarget(self, action: #selector(refreshContent), for: .valueChanged)
refreshControl.layer.zPosition = -1
if let refreshView = refreshControl.subviews.first {
let frame = refreshView.frame
refreshView.frame = CGRect(x: frame.origin.x, y: -(parallax.bounds.height / 2), width: frame.size.width, height: frame.size.height)
}
}
}
Now you will see your refresh control when pulling down, but the content inset will acting weird. In MXSegmentedPager.m
you need to prevent MXScrollView
from setting content inset in -(void)layoutContentView
with this code.
- (void)layoutContentView {
CGRect frame = self.bounds;
frame.origin = CGPointZero;
self.contentView.frame = frame;
self.contentView.contentSize = self.contentView.frame.size;
self.contentView.scrollEnabled = !!self.contentView.parallaxHeader.view;
if (!self.contentView.refreshControl.isRefreshing) {
self.contentView.contentInset = UIEdgeInsetsMake(self.contentView.parallaxHeader.height, 0, 0, 0);
}
}
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.