hons82/THSegmentedPager

the current page is not exactly right

btxkenshin opened this issue · 9 comments

follow this:

  1. turn to page 2
  2. use two fingers to do this: scroll to page 1,but not leave your finger, until over page 1, which means you have see the background color.
  3. then leave your fingers.

You will see the view controller is page 1,but the top bar still stoped with page 2

Unable to reproduce. I can't scroll over page1.
Os?
Device?
My sample project?
Sent from my iPhone

On 09.07.2015, at 09:59, btxkenshin notifications@github.com wrote:

follow this:

  1. turn to page 2
  2. use two fingers to do this: scroll to page 1,but not leave your finger, until over page 1, which means you have see the background color.
  3. then leave your fingers.

You will see the view controller is page 1,but the top bar still stoped with page 2


Reply to this email directly or view it on GitHub.

I think it has nothing to do with Os or Device
my os is 8.1
Device: both iphone 6 and sumilator
Yes:the sample project

And i have work on the same problem about using UIPageViewController to do this.also see some other app that do this,both of them have the same problem more or less.
And i think its a bug of Apple,of cal the exact page when using UIPageViewController but disable the default page control

The problem seems to be this and the solution provided is not what I want to implement.

A possible solution could be to set the selected tab before the transition actually finishes. So instead of setting it in

- (void)pageViewController:(UIPageViewController *)viewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed {
    if (completed){
        [self.pageControl setSelectedSegmentIndex:[self.pages indexOfObject:[viewController.viewControllers lastObject]] animated:YES];
    }
}

I'll push a solution that does it like this

- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers {
    [self.pageControl setSelectedSegmentIndex:[self.pages indexOfObject:[pendingViewControllers lastObject]] animated:YES];
}

Well, its a good try, i have also done this before. Yes, do the page change in the willTransitionToViewControllers can solve the problem which i describe exactly.

But there is another page error when quick scroll left and right, (with two fingers to make the continuously drag) and the reproduction is much more complecatied:

  1. turn to page 1
  2. use two fingers to do this: drag right to show the background color, do not leave you finger
  3. then drag left until page 3 is selected, but not drag too more, make sure page3 not show more then a half, (when page 3 is just show a little,perhaps 10 percent)do not leave you finger(note that you )
  4. then drag right until page 3 is disappear, you will see the page 1 is selected,just jump page 2, but the current view controller is exactly the second view controller.

It happens because when drag with two fingers to make the continuously scroll, the willTransitionToViewControllers is not called correctly.

So I'll probably need to combine didFinishAnimating and willTransitionToViewControllerto get the right behaviour...

Maybe, i have tried this with no solution. Have a try,and i am glad to discuss with you~~

Last night I made some tests and it seems like I need to set the pager index in willTransitionToViewController to get it right, and in case the transition did not complete to set it back

- (void)pageViewController:(UIPageViewController *)viewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed {
    if (!completed) {
        [self.pageControl setSelectedSegmentIndex:[self.pages indexOfObject:[viewController.viewControllers lastObject]] animated:YES];
    }
}

Drawback: The Pager is set before it is really needed which will trigger the delegate methods of the control

Actually even that one was not working, so I checked this solution with a couple of hacks and I hope it works now

Yeah, i have see the solution either, but i did not have a try. i just don't want to get it through this way, as you know its more or less dirty, and may not work in the future.
So, i still think its a bug of Apple.
Any way, if we have no choice, that's it and many Thanks!