Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPagerView scroll problems with UIScrollView

I have an UIPagerView with its View Controllers. Each UIViewController have an horizontal UIScrollView (with 3 horizontal images, for example). See the image for reference.

enter image description here

When i do a horizontal swipe gesture on the scrollview, the scrollview scrolls and the pagerview doesnt. When i do a horizontal swipe gesture in any view that is not the scrollview, the pagerview scrolls its child view controllers. Everything is fine by now.

What i want to achieve is: when i scroll the scrollview to the max value (its contentSize), i want the pagerview to scroll its viewcontrollers.

Please, how can i achieve this??

like image 371
guilherme.minglini Avatar asked Aug 04 '15 20:08

guilherme.minglini


1 Answers

To achieve what you have described, you need to set the pagerViewController as a delegate of your ScrollView.

Assuming that your ScrollView is a PageViewController, first make PagerViewController a PageViewControllerDelegate

@interface PagerViewController: UIViewController <UIPageViewControllerDelegate>

Then set the PagerViewController as the delegate of your ScrollView. Do this in viewDidLoad() method of PagerViewController

-(void) viewDidLoad
{ 
   //some other stuff
   self.scrollView.delegate = self
}

then implement didFinishAnimating delegate method in PagerViewController. It will be called whenever you scroll your scrollView controller, and you can figure out if its the last page you just scrolled by looking at the index of the latest controller. If it is, then trigger the code to scroll the PagerViewController to scroll on to the next view.

like image 180
dorian Avatar answered Oct 23 '22 18:10

dorian