UIPageViewController 检测平移手势

133*_*day 5 ios uipangesturerecognizer uipageviewcontroller

有没有办法确定 UIPageViewController 在左/右滑动时的平移位置?我一直在努力实现这一目标,但它不起作用。我添加了一个 UIPageViewController 作为子视图,我可以水平向左/右滑动它以在页面之间切换,但是我需要确定我在屏幕上平移的位置的 x,y 坐标。

133*_*day 5

我想出了如何做到这一点。基本上 UIPageViewController 使用 UIScrollViews 作为其子视图。我创建了一个循环并设置所有 UIScrollView 子视图,并将它们的委托分配给我的 ViewController。

/**
 *  Set the UIScrollViews that are part of the UIPageViewController to delegate to this class,
 *  that way we can know when the user is panning left/right
 */
-(void)initializeScrollViewDelegates
{
    UIScrollView *pageScrollView;
    for (UIView* view in self.pageViewController.view.subviews){
        if([view isKindOfClass:[UIScrollView class]])
        {
            pageScrollView = (UIScrollView *)view;
            pageScrollView.delegate = self;
        }
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSLog(@"Im scrolling, yay!");
}
Run Code Online (Sandbox Code Playgroud)