我有一个UIPageViewController
用来翻我的“书”。但是,每个图书页面都是一个ViewController
,其中一个UIScrollView
作为subview
。由于contentSize
,UIScrollView
只能垂直滚动。问题是,当用户垂直滚动scrollview
时,当scrollview
仍在滚动/减速时,用户无法翻页。一种非常简单的方法是滚动页面,然后尝试点击视图的边缘。这通常会更改页面,而且当scrollview
不移动时,它也会更改页面。但是,当它移动时,轻触会导致滚动视图停止移动,而不是翻页。
如果UIPageViewController
试图通过点击或平移页面来使用scrollviews
手势来翻页,我该如何取消该UIPageViewController
手势以生成翻页动画?
有关我想要实现的行为的示例,请查看iPhone上的推特官方客户端。当订阅源仍然从滚动减速时,可以从Timeline滑动到Discover。
发布于 2014-11-11 10:29:54
UIScrollView
滚动事件会阻止其他UIView
动画,所以在Twitter的情况下,他们可能会在滑动视图之前瞬间取消滚动。正如你在问题中所问的那样:
“如果UIPageViewController试图通过点击或平移页面来使用滚动视图手势来翻页,我该如何取消滚动视图手势?”
我会建议一个变通方法。
不依赖于UIPageViewController
固有的UIPanGestureRecognizer
,而是在页面视图中包含您自己的UIPanGestureRecognizer
,以便当在页面的适当部分检测到pan并以适当的方向执行时,新的UIPanGestureRecognizer
将覆盖UIPageViewController
的UIGestureRecognizer
并触发必要的操作。具体而言,您需要:
(1)使用停止滚动动画
CGPoint offset = scrollView.contentOffset;
[scrollView setContentOffset:offset animated:NO];
(2)使用编程方式翻页
- (void)setViewControllers:(NSArray *)viewControllers direction:
(UIPageViewControllerNavigationDirection)direction animated:
(BOOL)animated completion:(void (^)(BOOL finished))completion;
从而在一个流畅的平移手势内停止滚动动画和完成翻页。
发布于 2014-04-25 02:01:43
通过使用requireGestureRecognizerToFail:方法,UIGestureRecognizer
类可以设置对其他手势识别器的依赖。
在您的示例中,此方法可以按如下方式使用:
for (UIGestureRecognizer *gestureRecognizer in pageController.gestureRecognizers) {
for (ViewController *viewController in viewControllers) {
for (UIGestureRecognizer *gestureRecognizerForFail in viewController.scrollView.gestureRecognizers) {
[gestureRecognizerForFail requireGestureRecognizerToFail:gestureRecognizer];
}
}
}
发布于 2014-03-09 05:07:30
我也有同样的问题,我一直在想办法...在我的例子中,我的pdf文件启用了缩放功能。所以我举了个例子:
[scrollView setMaximumZoomScale:6];
[scrollView setMinimumZoomScale:1];
当我初始化控制器和它的scrollView时,就在那之后,每次我改变方向或页面时,我改变缩放以适合页面的宽度,只有当缩放是“很远”的时候。
CGFloat desiredWidth = scrollView.frame.size.width/pdfRect.size.width;
if (desiredWidth>[self zoomScale]) {
[scrollView setZoomScale:desiredWidth animated:YES];
}
我希望它能帮上忙
https://stackoverflow.com/questions/13241736
复制相似问题