1

我有一点关于UIPageViewControllers. 看起来它完全符合我的要求,但有些事情我不确定。我想也许有人在那里可能有一两颗宝石可以分享。:)

所以这里是:我想用PageViewCtl纵向或横向模式显示内容,但是,无论设备是什么方向,它们都必须在同一个控制器中(即具有相同的视图)。原因是内容必须以这样一种方式(横向)可缩放,即内容的两个“页面”都可以同时缩放,而不是单独缩放。在这一点上,我真的看不出这是如何处理的PageViewCtl,因为据我所知,你不能在 2 个视图控制器之间共享一个视图。那么有人对这个问题有任何见解吗?非常感谢提前!

4

1 回答 1

0

我从 Erica Sadun (https://github.com/erica/iOS-5-Cookbook) 那里偷了这个:

    // Update interface to the given page
- (void) fetchControllersForPage: (uint) requestedPage orientation: (UIInterfaceOrientation) orientation
{
    BOOL sideBySide = [self useSideBySide:orientation];
    int numberOfPagesNeeded = sideBySide ? 2 : 1;
    int currentCount = self.viewControllers.count;

    uint leftPage = requestedPage;
    if (sideBySide && (leftPage % 2)) leftPage--;

    // Only check against current page when count is appropriate
    if (currentCount && (currentCount == numberOfPagesNeeded))
    {
        if (pageNumber == requestedPage) return;
        if (pageNumber == leftPage) return;
    }

    // Decide the prevailing direction by checking the new page against the old
    UIPageViewControllerNavigationDirection direction = (requestedPage > pageNumber) ? UIPageViewControllerNavigationDirectionForward : UIPageViewControllerNavigationDirectionReverse;
    [self updatePageTo:requestedPage];

    // Update the controllers
    NSMutableArray *pageControllers = [NSMutableArray array];
    SAFE_ADD(pageControllers, [self controllerAtPage:leftPage]);    
    if (sideBySide)
        SAFE_ADD(pageControllers, [self controllerAtPage:leftPage + 1]);

    [self setViewControllers:pageControllers direction: direction animated:YES completion:nil];
}

// Entry point for external move request
- (void) moveToPage: (uint) requestedPage
{
    [self fetchControllersForPage:requestedPage orientation:(UIInterfaceOrientation)[UIDevice currentDevice].orientation];
}

#pragma mark Delegate

- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
    NSUInteger indexOfCurrentViewController = 0;
    if (self.viewControllers.count)
        indexOfCurrentViewController = ((UIViewController *)[self.viewControllers objectAtIndex:0]).view.tag;
    [self fetchControllersForPage:indexOfCurrentViewController orientation:orientation];

    BOOL sideBySide = [self useSideBySide:orientation];
    self.doubleSided = sideBySide;

    UIPageViewControllerSpineLocation spineLocation = sideBySide ? UIPageViewControllerSpineLocationMid : UIPageViewControllerSpineLocationMin;
    return spineLocation;
}

给她一点爱。并注意超级聪明的“if (sideBySide && (leftPage % 2)) leftPage--;”,它确保左页始终是奇数页。

-一个

于 2011-11-22T12:34:40.207 回答