Disable UIPageViewController bounce

前端 未结 13 2412
离开以前
离开以前 2020-11-27 04:08

Searched a lot for this one, but couldn\'t find a proper solution yet.

Is it possible to disable the bounce effect of a UIPageViewController and still

13条回答
  •  隐瞒了意图╮
    2020-11-27 04:36

    Edit: Do not use this solution. I learned afterwards that this introduces a bug where about 5% of the time, the user can't page in the same direction. They have to page back, then forward again to continue.

    If you're using a UIPageViewControllerDataSource, a relatively simple workaround (and a bit hacky) is to disable bouncing each time the pageViewController:viewControllerBeforeViewController: delegate method is called. Here is an example implementation:

    @interface YourDataSourceObject ()
    @property (strong, nonatomic) UIScrollView *scrollView;
    @end
    
    @implementation
    - (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController {
        if (!self.scrollView) {
            for (UIView *view in pageViewController.view.subviews) {
                if ([view isKindOfClass:[UIScrollView class]]) {
                    self.scrollView = (UIScrollView *)view;
                }
            }
        }
        self.scrollView.bounces = NO;
    
        // Your other logic to return the correct view controller. 
    }
    @end
    

提交回复
热议问题