简体   繁体   中英

UIPageViewControllerDelegate - willTransitionToViewControllers replacement for iOS 5

I'm using

- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers

to track current visible page in a UIPageViewController . This method is available from iOS 6 but I need to achieve this also in iOS 5 , how could I do that? I tried with

- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed

but previousViewControllers count is always one, so it's no help or probably I'm missing something

The UIPageViewController can show two UIViewController instances when it has its spine location at UIPageViewControllerSpineLocationMid ,otherwise it shows one.

To get a reference to the view controller currently going out of the view, you can have it via the previousViewControllers parameter in its delegate. It will contain the references to the view controllers previously being shown on screen.

For eg. if you have MyContentViewController class which is being passed in your page view controller's datasource methods, you can get the reference to the view controller which is going out of screen in the delegate as:

MyContentViewController *myVC = (MyContentViewController*)[previousViewControllers objectAtIndex:0];

And to get the reference to current view controller, use viewControllers property of UIPageViewController .

MyContentViewController *myVC = (MyContentViewController*)[[self.pageViewController viewControllers] objectAtIndex:0];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM