将UIPageViewController(使用TransitionStyleScroll)平移手势限制到某个区域

时间:2014-01-30 16:20:36

标签: objective-c cocoa-touch uigesturerecognizer uipageviewcontroller

在我的应用程序中,我有一个RootPageViewController,它包含UIPageViewController和一个或多个DetailPageViewController,UITableView作为子视图。

                          DetailPageViewController
                        / 
RootPageViewController  - DetailPageViewController
                        \
                          DetailPageViewController

在每个DetailPageViewController的顶部是一个小空间,应该可以滑动并转到下一个DetailPageViewController。

 ------------------- 
|                   |
|                   |  -> UIPageViewController should respond to pan's
|                   |
|-------------------|   --------------------------------------------
|  CellContent      |  
|-------------------|
|  CellContent      |
|-------------------|  -> UIPageViewController should disable UIPageViewController pan's
|  CellContent      |
|-------------------|
|  ...              |

在iOS 7天气应用程序中是一个滚动视图,其中包含整个弱预测,不知何故会覆盖或禁用UIPageViewController的平底锅。

如何重新创建此类行为?

很抱歉找不到截图

2 个答案:

答案 0 :(得分:4)

我通过继承UIPageViewController,找到它的UIScrollView(迭代self.subviews),并向该scrollView添加一个新的UIPanGestureRecognizer来实现。

我将我的子类UIPageViewController设置为该新UIPanGestureRegognizer的委托。然后我实现了两个委托方法:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
  return NO;
}

并在

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer

我决定是否要“吃掉事件”(回复是)或者我是否希望UIScrollView的原始UIPanGestureViewRecognizer处理它(回复否)。因此,YES-reply意味着UIPageViewController不会滚动到下一个ViewController。

答案 1 :(得分:1)

我在Swift中的解决方案:

let myview = UIView(frame: CGRect(x:0, y:0, width:320, height:320))
//dummy view that defines the area where the gesture works
self.view.addSubview(myview)

for x in self.pageViewController!.view.subviews 
{ if x is UIScrollView
  { myview.addGestureRecognizer(x.panGestureRecognizer) } 
}