Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPageViewController didFinishAnimating not called if swiped quickly

I have a UIPageViewController that works as expected. I can scroll left and right and the delegate method didFinishAnimating is called when I scroll each direction. However, if I scroll too quickly I end up on a page where didFinishAnimating is not called, though it is called for all previous pages. Does anyone know why this might be happening?

I would think that didFinishAnimating would be called on every page transition regardless (e.g., even if the turn was aborted).

like image 753
mattnedrich Avatar asked Jun 17 '14 14:06

mattnedrich


2 Answers

This bug is still here in 2017.. I tried many alternative ways.. now I gave up the hope that this will be fixed by Apple and I think the best way is to use protocol to bound UIPageViewController with content ViewController, so we can notify UIPageViewController in viewDidAppear()

like image 196
xiaoyu Avatar answered Oct 12 '22 18:10

xiaoyu


I've got the same issue. I tried to use the UIScrollView delegate instead of UIPageViewController to solve the issue. This is a tricky method, not recommend to use.

1.get the UIScrollView in UIPageViewController to set delegate:

for (UIView *view in self.view.subviews) {
    if ([view isKindOfClass:[UIScrollView class]]) {
        UIScrollView *scroll = (UIScrollView *) view;
        scroll.delegate = self;
    }
}

2.override scrollViewWillBeginDragging:(UIScrollView *)scrollView

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
    [[NSNotificationCenter defaultCenter] postNotificationName:PageSwitchingBegan
                                                    object:nil];
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    [[NSNotificationCenter defaultCenter] postNotificationName:PageSwitchingEnded
                                                    object:nil];
}

You may also try override - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView instead of scrollViewDidEndDragging to achieve better result.

like image 2
chakming Avatar answered Oct 12 '22 16:10

chakming