【问题标题】:Scroll UIPageViewController when contained scrollview is zoomed, like Apple's PhotoScroller example缩放包含的滚动视图时滚动 UIPageViewController,如 Apple 的 PhotoScroller 示例
【发布时间】:2014-05-11 07:24:32
【问题描述】:

在苹果 PhotoScroller 示例中,UIPageViewController 中显示了 3 个可缩放图像。您可以缩放这些图像并在它们之间进行页面缩放即使它们仍处于缩放状态。我的应用程序使用来自 PhotoScroller 的代码,唯一的区别是我的 UIPageViewController 是我的应用程序中另一个 UIViewController 的子视图控制器 - 即分页功能包含在视图层次结构中。在 Apple 的版本中,UIPageViewController 是根视图控制器(实际上由情节提要设置)。在我的代码中,除非我将内容返回到未缩放的比例,否则我不会获得分页行为。对于我的应用程序,我不想强​​迫用户这样做。我需要做些什么才能让它按我想要的方式工作?

更新 我已经确定手动将页面视图控制器设置为根视图控制器会导致苹果示例代码表现出不需要的行为。即在应用委托中创建页面视图控制器为

        // 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;

使缩放的图像仅在边缘反弹,而不是缩放到下一张图像。原代码为:

// 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];

为什么这会破坏图像缩放时的滚动行为?

已解决

UIPageViewController 必须正确启动,因为

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

我只是打电话给alloc] init]

【问题讨论】:

  • 您是否可以添加一些代码或者可以将示例项目添加到 Github?谢谢。
  • 让我看看我能做什么。

标签: ios uiscrollview uipageviewcontroller


【解决方案1】:

为了在放大图像时浏览您的UIPageViewController,我建议创建单独的可缩放UIScrollviews 以包含每个单独的图像,然后将它们作为子视图添加到分页的每个页面(并且不可缩放) UIScrollview;这样,通过分离手势接收器,您可以在分页时保持放大图像。

【讨论】:

  • 这正是我正在做的事情,也正是 PhotoScroller 示例所做的事情,但我没有得到我想要的行为。不过感谢您的回信,我将很快更新一个包含示例代码的 github 项目,以便我们可以解决这个问题。
  • @deepwinter 好的,我明白了。当您平移图像时,您是否也希望图像平移?或者你只是想让页面移动到下一个?我之所以问,是因为您的内部 UIScrollview 固有的 UIPanGestureRecognizer 似乎正在捕捉为您的外部 UIScrollview 准备的平底锅......根据您的目标,有一些方法可以解决这个问题。
【解决方案2】:

UIPageViewController必须正确启动,因为

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

我只是调用了alloc] init] 来代替storyboard,这还不够。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-11
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    相关资源
    最近更新 更多