Scroll UIPageViewController when contained scrollview is zoomed, like Apple's PhotoScroller example

StackOverflow https://stackoverflow.com/questions/23590076

Pergunta

In the apple PhotoScroller example, 3 zoomable images are displayed in a UIPageViewController. You can zoom these images and page between them even when they are still zoomed. My application uses the code from the PhotoScroller with the only difference being that my UIPageViewController is a child view controller of another UIViewController in my app - i.e. the paging functionality is contained within a view hierarchy. In Apple's version, the UIPageViewController is the root view controller (set up by a storyboard actually). In my code, I do not get the paging behavior unless I return the content to it's un-zoomed scale. For my app I don't want to force the user to do this. What do I need to do to get this working the way I want to?

UPDATE I have determined that setting the page view controller as the root view controller manually causes the apple example code to exhibit the unwanted behavior. that is, creating the page view controller in app delegate as

        // assign the first page to the pageViewController (our rootViewController)
    UIPageViewController *pageViewController = [[UIPageViewController alloc] init];
    pageViewController.dataSource = self;

    [pageViewController setViewControllers:@[pageZero]
                                  direction:UIPageViewControllerNavigationDirectionForward
                                   animated:NO
                                 completion:NULL];
    self.window.rootViewController = pageViewController;

Causes a zoomed image to simply bounce at the edge, rather than zooming to the next image. Original code is:

// assign the first page to the pageViewController (our rootViewController)
    UIPageViewController *pageViewController = (UIPageViewController *)self.window.rootViewController;
    pageViewController.dataSource = self;

    [pageViewController setViewControllers:@[pageZero]
                                  direction:UIPageViewControllerNavigationDirectionForward
                                   animated:NO
                                 completion:NULL];

Why does this break the behavior of scrolling while an image is zoomed ?

SOLVED

UIPageViewController must be initted properly, as

        _pageViewController =  [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];

I had merely called alloc] init].

Foi útil?

Solução 2

UIPageViewController must be initiated properly, as

        _pageViewController =  [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];

I had merely called alloc] init] as a replacement for storyboard, which is not sufficient.

Outras dicas

In order to page through your UIPageViewControllereven when zoomed into your images, I suggest creating separate zoomable UIScrollviews to contain each individual image then adding them as subviews to each page of the paging (and non-zoomable) UIScrollview; this way, by separating the gesture receivers, you can stay zoomed into the image while paging.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top