我正在尝试为我的应用实现类似通知中心的功能:
有一个 UIPageViewController
,因为我想让左/右滑动手势起作用,并且在里面我需要显示 4 个 UITableViewControllers
。顶部有一个 UISegmentedCotrol
来显示“选择了哪个选项卡”
一切正常,除了用于更改页面的滑动手势,就好像 TableView 正在捕获手势而不是让 PageView 完成它的工作。
我不需要我的 TableView 是可编辑的,因为它们只是来自网站的文章。只有 didSelectRowAt(indexPath)
足以执行我需要的任何操作(转至“articleViewController”)。
如果有人知道如何让 UIPageViewController
的手势与 TableViewController
一起工作,请告诉我。谢谢
最佳答案
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
}
}
}
关于ios - 手势不适用于包含 UITableViewControllers 的 UIPageViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44105528/