2017-05-08 157 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