Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the current page is not exactly right #12

Closed
btxkenshin opened this issue Jul 9, 2015 · 9 comments
Closed

the current page is not exactly right #12

btxkenshin opened this issue Jul 9, 2015 · 9 comments

Comments

@btxkenshin
Copy link

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

@hons82
Copy link
Owner

hons82 commented Jul 9, 2015

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 [email protected] 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.

@btxkenshin
Copy link
Author

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

@hons82
Copy link
Owner

hons82 commented Jul 13, 2015

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];
}

hons82 added a commit that referenced this issue Jul 13, 2015
@btxkenshin
Copy link
Author

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.

@hons82
Copy link
Owner

hons82 commented Jul 14, 2015

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

@btxkenshin
Copy link
Author

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

@hons82
Copy link
Owner

hons82 commented Jul 30, 2015

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

hons82 added a commit that referenced this issue Jul 30, 2015
Still not perfect solution
hons82 added a commit that referenced this issue Jul 30, 2015
Now it tries to get the current index wherever possible
@hons82
Copy link
Owner

hons82 commented Jul 30, 2015

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

@hons82 hons82 closed this as completed Aug 3, 2015
@btxkenshin
Copy link
Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants