2017-05-08 156 views
0

我有一個帶有四個選項卡的UIPageViewController。三張桌子和一個webview。問題是垂直滾動不起作用。我如何使用swift解決這個問題?UIPageViewController:表垂直滾動不起作用

這是我的代碼:

func createTxtPageViewController() { 

     let pageController = self.storyboard!.instantiateViewControllerWithIdentifier("pagetxtController") as! UIPageViewController 
     pageController.dataSource = self 
     pageController.delegate = self 

     if texts.count > 0 { 
      let firstController = getItemTxtController(0)! 
      let startingViewControllers = [firstController] 
      pageController.setViewControllers(startingViewControllers, direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil) 
     } 

     pageTxtViewController = pageController 
     pageTxtViewController?.view.frame = CGRectMake(10, 173, self.rightView.frame.size.width - 20, self.rightView.frame.size.height - 183) 

     addChildViewController(pageTxtViewController!) 
     self.rightView.addSubview(pageTxtViewController!.view) 
     pageTxtViewController!.didMoveToParentViewController(self) 
    } 
+0

嘗試更改順序添加容器意見'self.rightView.addSubview(pageTxtViewController!.view)''然後addChildViewController(pageTxtViewController!)' –

+0

@KhalidAfridi這不行 – breno

+0

你已經在刷卡功能的pageViewController? –

回答

0

如果你已經添加了PanGestureRecognizer它試圖覆蓋的tableView的手勢識別你所要做的使用UIGestureRecognizerDelegate手動檢查。

let pangGesture = UIPanGestureRecognizer(target: self, action: #selector(createTxtPageViewController(recognizer:))) 
pangGesture.delegate = self 
self.view.addGestureRecognizer(pangGesture) 

,那麼你必須實現gestureRecongizerShouldBegin委託功能

func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { 

    // we check for panGesture if it's panGesture we continue if not return   
    guard let recognizer = gestureRecognizer as? UIPanGestureRecognizer else { 
     return true 
    } 

    // The velocity of the pan gesture in the coordinate system of the specified view. 
    let velocity = recognizer.velocity(in: self.view) 

    // If velocity.y is greater than velocity.x user is trying to scroll tableView else user wants to swipe to next screen 
    return abs(velocity.y) > abs(velocity.x) ? false : true 
} 

在類的頂部聲明CGPoint屬性touchLocation

var panStartPoint: CGPoint! 

現在你createTxtPageViewController功能檢查內部爲狀態和檢測用戶向左或向右滑動方向

func createTxtPageViewController(recognizer: UIPanGestureRecognizer) { 


    switch recognizer.state { 
    case .began: 
     touchLocation = recognizer.location(in: self.view) 
    case .changed: 
     let currentPoint = recognizer.location(in: self.view) 
     let swipingLeft = currentPoint.x < touchLocation.x ? true : false 

     if !swipingLeft { 
      // swiped right 
      //TODO: Add your logic for navigation to nextViewController 
     } else { 
      // swiped left 
      //TODO: Add your logic for navigation to nextViewController 
     } 
     // you can check for other states as well and clean up after your self e.g state.cancelled I just break 
    default: 
     break 
    } 

} 
+0

對不起,但我不明白。我將用手勢替換我的UIPageViewController? – breno

+0

我想你已經在你的UIPageViewController中刷過手勢了? –

+0

是的,我有它,它的工作原理。我不明白爲什麼重做用於創建UIPageViewController的「createTxtPageViewController」方法。 – breno