Ios 手势不适用于包含UITableViewController的UIPageViewController
我正在尝试为我的应用程序实现类似通知中心的功能: 有一个Ios 手势不适用于包含UITableViewController的UIPageViewController,ios,swift,uitableview,uigesturerecognizer,uipageviewcontroller,Ios,Swift,Uitableview,Uigesturerecognizer,Uipageviewcontroller,我正在尝试为我的应用程序实现类似通知中心的功能: 有一个UIPageViewController,因为我想让左/右滑动手势正常工作,在里面我需要显示4个UITableViewControllers。顶部有一个UISegmentedCotrol显示“选择了哪个选项卡” 除了用于更改页面的滑动手势之外,一切都正常工作,就好像TableView正在捕获手势而不让PageView完成它的工作一样 我不需要我的TableView是可编辑的,因为它们只是来自网站的文章。只有didSelectRowAt(in
UIPageViewController
,因为我想让左/右滑动手势正常工作,在里面我需要显示4个UITableViewControllers
。顶部有一个UISegmentedCotrol
显示“选择了哪个选项卡”
除了用于更改页面的滑动手势之外,一切都正常工作,就好像TableView正在捕获手势而不让PageView完成它的工作一样
我不需要我的TableView是可编辑的,因为它们只是来自网站的文章。只有didSelectRowAt(indexPath)
就足以完成我需要做的任何事情(转到“articleViewController”)
如果有人知道如何让
UIPageViewController
的手势与TableViewController
一起工作,请告诉我。谢谢
var pageviewController=UIPageViewController()
谢谢,但这在我的情况下不起作用…我正在从序列图像板实例化PageViewController,并在代码中实例化每个TableViewController。我希望保留默认行为(能够在“页面”之间以可视方式滑动),如果我不使用TableViewController,这会起作用(甚至当从普通UIViewController切换到UITableViewController时)但不是相反的方式谢谢,但这在我的情况下不起作用…我正在从Storyboard中实例化PageViewController,并在代码中实例化每个TableViewController。我希望保留默认行为(能够在“页面”之间直观地滑动),如果我不使用TableViewController(甚至在从普通UIViewController切换到UITableViewController时),该选项也可以使用但不是相反的方法。我建议任何有类似情况的人使用图书馆,因为它会处理所有的麻烦。我建议任何有类似情况的人使用图书馆,因为它会处理所有的麻烦。
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
}
}
}