maxep / MXSegmentedPager

Segmented pager view with Parallax header
MIT License
1.27k stars 252 forks source link

Laggy animations when scrolling #115

Closed BananaPukeh closed 7 years ago

BananaPukeh commented 8 years ago

When scrolling between views and release your thumb, the animation is kind of laggy. I've noticed this on a iPhone 6 and a iPad Mini 2. The 6S and the simulator don't seem laggy.

I did some research and ended up on the delegate callbacks from the MXPagerView to the HMSegmentedControl.

When you comment the -setSelectedSegmentIndex:animated: in the willMoveToPageAtIndex: the animation isn't laggy anymore. I guess the lag is caused by the HMSegmentedControl's CATransaction animation beging triggered while the MXPagerView is still animating.

Is there anyone who knows how to fix these async animations? :)

#pragma mark <MXPagerViewDelegate>

- (void)pagerView:(MXPagerView *)pagerView willMoveToPageAtIndex:(NSInteger)index {
    [self.segmentedControl setSelectedSegmentIndex:index animated:YES];
}

- (void)pagerView:(MXPagerView *)pagerView didMoveToPageAtIndex:(NSInteger)index {
    [self.segmentedControl setSelectedSegmentIndex:index animated:NO];
    [self changedToIndex:index];
}

MXSegmentedPager line 239

loki187 commented 8 years ago

+1. Same issue here. Tested on iPhone 6s. I have 4 tabs with tableview and laggy are very unpleasant.

dkalaitzidis commented 7 years ago

A workaround that i used to deal with the same issue:

In MXPagerView.m in -(void)layoutSubviews i used a for loop on _count to load all my controllers with loadPageAtIndex

I removed the [self unLoadHiddenPages] and the if statement with loadPage(index -1) etc...

I know it's not the best case, but in my case it does the job that i want.