6

在我的應用程序中,我有一個RootPageViewController,它包含UIPageViewController和一個或多個具有UITableView作爲子視圖的DetailPageViewController。將UIPageViewController(使用TransitionStyleScroll)平移手勢限制在某個區域

      DetailPageViewController 
         /
RootPageViewController - DetailPageViewController 
         \ 
          DetailPageViewController 

在每個DetailPageViewController的頂部是一個小空間,應該可以刷卡,並進入下一個DetailPageViewController。

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

在搭載iOS 7的天氣應用程序是與整個弱預測誰莫名其妙地覆蓋或禁用的UIPageViewController的油鍋滾動視圖。

我該如何重新創建這樣的行爲?

對不起失蹤的截圖

回答

4

我通過繼承UIPageViewController,找到自己的UIScrollView(迭代self.subviews),並增加了新的UIPanGestureRecognizer到滾動視圖做到這一點。

我將我的子類UIPageViewController設置爲該新UIPanGestureRegognizer的代表。然後,我實現兩個委託方法:

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

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer 

我決定,如果我要「吃事件」(回答YES),或者如果我想的UIScrollView原UIPanGestureViewRecognizer處理它(答覆否)。所以,YES-reply意味着UIPageViewController不會滾動到下一個ViewController。

+2

http://www.lukaszielinski.de/blog/posts/2014/03/26/restrict-panning-of-uipageviewcontroller-to-certain-area/ 在這裏有很多詳細的答案,說同樣的事情 –

+0

謝謝你們:) – ioboi

+0

好吧,不需要添加額外的panGestureRecognizer!您可以使用提供的行爲來執行相同的行爲,而無需執行所有此手勢RecognidesHouldRecognizeSimultaneouslyWithGestureRecognizer:business ... ;-) – mramosch

0

我在斯威夫特的解決方案:

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) } 
} 
相關問題