1337holiday 1337holiday - 4 months ago 58
iOS Question

UIPageViewController detecting pan gestures

Is there a way to determine the panning location of a UIPageViewController while sliding left/right? I have been trying to accomplish this but its not working. I have a UIPageViewController added as a subview and i can slide it horizontally left/right to switch between pages however i need to determine the x,y coordinates of where I am panning on the screen.


I figured out how to do this. Basically a UIPageViewController uses UIScrollViews as its subviews. I created a loop and set all the subviews that are UIScrollViews and assigned their delegates to my 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
    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!");