我正在尝试为我的应用实施类似通知中心的内容:
有一个UIPageViewController
,因为我想要向左/向右滑动手势,我需要显示4 UITableViewControllers
。最上面有一个UISegmentedCotrol
来显示“选择了哪个标签”
除了用于更改页面的滑动手势外,一切正常,就好像TableView正在捕捉手势而不让PageView完成其工作。
我不需要我的TableViews可编辑,因为它们只是来自网站的文章。只有didSelectRowAt(indexPath)
足以做我需要的任何事情(转到“articleViewController”)。
如果有人知道如何让UIPageViewController
的手势与TableViewController
内部合作让我知道。谢谢
答案 0 :(得分:0)
var pageviewController = UIPageViewController()
pageviewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: nil)
pageviewController.view.frame = CGRect(x: 0, y: 0, width: 320 , height: 568)
pageviewController.setViewControllers([arrayControllers[0]], direction: .forward, animated: false, completion: nil)
addChildViewController(pageviewController)
viewToAdd.addSubview(pageviewController.view)
pageviewController.didMove(toParentViewController: self)
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
swipeRight.direction = UISwipeGestureRecognizerDirection.right
self.view.addGestureRecognizer(swipeRight)
let swipeLeft = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
swipeLeft.direction = UISwipeGestureRecognizerDirection.left
self.view.addGestureRecognizer(swipeLeft)
func respondToSwipeGesture(gesture: UIGestureRecognizer) {
if let swipeGesture = gesture as? UISwipeGestureRecognizer {
switch swipeGesture.direction {
case UISwipeGestureRecognizerDirection.right:
//right view controller
print("Swipe Right")
case UISwipeGestureRecognizerDirection.left:
//left view controller
print("Swipe left")
default:
break
}
}
}