限制UIPageViewController(使用TransitionStyleScroll)平移手势到某个区域 [英] Restrict UIPageViewController (with TransitionStyleScroll) pan gesture to a certain area

查看:571
本文介绍了限制UIPageViewController(使用TransitionStyleScroll)平移手势到某个区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  DetailPageViewController 
/
RootPageViewController - DetailPageViewController
\
DetailPageViewController

在每个DetailPageViewController的顶部是一个有点空间,应该可以滑动并进入下一个DetailPageViewController。

  ------------------- 
| |
| | - > UIPageViewController应该响应pan的
| |
| ------------------- | --------------------------------------------
| CellContent |
| ------------------- |
| CellContent |
| ------------------- | - > UIPageViewController应该禁用UIPageViewController pan的
| CellContent |
| ------------------- |
| ... |

在iOS 7天气应用程序是一个scrollview与整个弱预测不知何故覆盖或禁用



对于缺少的屏幕截图,



>

解决方案

我通过子类化UIPageViewController,找到它的UIScrollView(iterate self.subviews),并添加一个新的UIPanGestureRecognizer到该scrollView。 / p>

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

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

   - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer 

我决定是否要吃事件(回答YES),或者如果我想要UIScrollView的原始UIPanGestureViewRecognizer处理它(回答NO)。因此,YES-reply意味着UIPageViewController不会滚动到下一个ViewController。


In my app I have a RootPageViewController which contains the UIPageViewController and one or more DetailPageViewController with a UITableView as a childview.

                          DetailPageViewController
                        / 
RootPageViewController  - DetailPageViewController
                        \
                          DetailPageViewController

On top of every DetailPageViewController is a little space where it should be possible to swipe and get to the next DetailPageViewController.

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

In the iOS 7 weather app is a scrollview with the whole weak forecast who somehow overwrites or disables the the pan of the UIPageViewController.

How can I recreate such behavior ?

Sorry for the missing screenshots

解决方案

I do it by subclassing the UIPageViewController, finding its UIScrollView (iterate self.subviews), and adding a new UIPanGestureRecognizer to that scrollView.

I set my subclassed UIPageViewController to be the delegate of that new UIPanGestureRegognizer. I then implement two delegate methods:

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

and in

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer

I decide if I want to "eat the event" (reply YES) or if I want the original UIPanGestureViewRecognizer of the UIScrollView to handle it (reply NO). So, the YES-reply means the UIPageViewController will not scroll to the next ViewController.

这篇关于限制UIPageViewController(使用TransitionStyleScroll)平移手势到某个区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆