GetPreviousViewController() public method

public GetPreviousViewController ( UIPageViewController pageViewController, UIViewController referenceViewController ) : UIViewController
pageViewController UIPageViewController
referenceViewController UIViewController
return UIViewController
        public UIPageViewControllerSpineLocation GetSpineLocation(UIPageViewController pageViewController, UIInterfaceOrientation orientation)
        {
            if (orientation == UIInterfaceOrientation.Portrait || UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
            {
                UIViewController currentViewController = pageViewController.ViewControllers [0];
                pageViewController.SetViewControllers(
                    new [] { currentViewController },
                    UIPageViewControllerNavigationDirection.Forward,
                    true, null
                    );

                pageViewController.DoubleSided = false;
                return(UIPageViewControllerSpineLocation.Min);
            }

            var dataViewController           = (DataViewController)pageViewController.ViewControllers [0];
            var indexOfCurrentViewController = modelController.IndexOfViewController(dataViewController);

            UIViewController[] viewControllers = null;

            if (indexOfCurrentViewController == 0 || indexOfCurrentViewController % 2 == 0)
            {
                UIViewController nextViewController = modelController.GetNextViewController(pageViewController, dataViewController);
                viewControllers = new [] { dataViewController, nextViewController };
            }
            else
            {
                UIViewController previousViewController = modelController.GetPreviousViewController(pageViewController, dataViewController);
                viewControllers = new[] { dataViewController, previousViewController };
            }

            pageViewController.SetViewControllers(viewControllers, UIPageViewControllerNavigationDirection.Forward, true, null);
            return(UIPageViewControllerSpineLocation.Mid);
        }
Beispiel #2
0
        public UIPageViewControllerSpineLocation GetSpineLocation(UIPageViewController pageViewController, UIInterfaceOrientation orientation)
        {
            var result = UIPageViewControllerSpineLocation.None;

            if (orientation == UIInterfaceOrientation.Portrait || UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
            {
                // In portrait orientation or on iPhone: Set the spine position to "min" and the page view controller's view controllers array to contain just one view controller.
                // Setting the spine position to 'UIPageViewControllerSpineLocationMid' in landscape orientation sets the doubleSided property to YES, so set it to NO here.
                var currentViewController = pageViewController.ViewControllers[0];
                pageViewController.SetViewControllers(new[] { currentViewController },
                                                      UIPageViewControllerNavigationDirection.Forward,
                                                      true,
                                                      null);

                pageViewController.DoubleSided = false;
                result = UIPageViewControllerSpineLocation.Min;
            }
            else
            {
                // In landscape orientation: Set set the spine location to "mid" and the page view controller's view controllers array to contain two view controllers.
                // If the current page is even, set it to contain the current and next view controllers; if it is odd, set the array to contain the previous and current view controllers.
                var dataViewController             = pageViewController.ViewControllers[0] as DataViewController;
                var indexOfCurrentViewController   = modelController.IndexOfViewController(dataViewController);
                UIViewController[] viewControllers = null;

                if (indexOfCurrentViewController == 0 || indexOfCurrentViewController % 2 == 0)
                {
                    var nextViewController = modelController.GetNextViewController(pageViewController, dataViewController);
                    viewControllers = new[] { dataViewController, nextViewController };
                }
                else
                {
                    var previousViewController = modelController.GetPreviousViewController(pageViewController, dataViewController);
                    viewControllers = new[] { dataViewController, previousViewController };
                }

                pageViewController.SetViewControllers(viewControllers, UIPageViewControllerNavigationDirection.Forward, true, null);
                result = UIPageViewControllerSpineLocation.Mid;
            }

            return(result);
        }