Smooth Transition with UIPageViewController and UI

2019-04-14 22:48发布

问题:

In an app that im currently developing im switching between two UITableViewController's with a UISegmentedControl inside the UINavigationBar. The new Apple Music has a very neat effect where a user switches between UIViewController's inside a UIPageViewController. The associated UISegmentedControl adjusts smoothly to this. How should a basic storyboard setup or code base look to achieve something like this?

回答1:

you need to use uipageviewcontroller & uisegmentedcontrol in the following manner

  1. take uipageviewcontroller & see this tutorial for its integration http://www.appcoda.com/uipageviewcontroller-storyboard-tutorial/

  2. after that if you want to perform the transition between two views only when user clicks on the uisegment button the do not implement this delegate

    • (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController

    • (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController

  3. set the transition style to scroll

  4. now you need to customise the uisegmentedcontrol to give the pressing event animation

  5. on the click event of the button perform set the view controller you need to display with this code

[youPagecontrollerObject setViewControllers:object direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];

6 build & run