UIPageViewController within NavigationController

后端 未结 4 726
耶瑟儿~
耶瑟儿~ 2020-12-23 10:54

I\'ve read every tutorial I\'ve found about UIPageViewController, but they show just basics, I\'d like to create something like new twitter app has:

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-23 11:22

    I had a very similar setup and solved the problem.

    My setup is that I have a UIPageViewController inside a UINavigationController because I wanted the navigation bar to be persistent while I swiped between each view controller. I wanted the title of the current UIViewController inside the UIPageViewController to become the title of the UINavigationController.

    The way to do this is to implement the UIPageViewControllerDelegate method pageViewController didFinishAnimating which triggers after a change to a view controller is made from the UIPageViewController. You can probably see where this going: From here, set the navigationItem.title property of the UIViewPageController, which the UINavigationController uses to set it's own title, with that of the current view controller's title.

    Example:

    - (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
    {
        if(finished && completed)
        {
            NSString *titleOfIncomingViewController = [[pageViewController.viewControllers firstObject] title];
            pageViewController.navigationItem.title = titleOfIncomingViewController;
        } 
    }
    

    NB: This delegate method triggers only off gesture-initiated scrolls.

提交回复
热议问题