我已经创建了PageViewController
,我正在尝试进行测验,当您按下按钮时,它将滑动到下一个视图。我似乎无法让这个工作。到目前为止,我添加了一个包含按钮的tableView,我想用这个手势。除此之外我想禁用滚动手势,因此用户无法手动滚动。这是可能的还是使用scrollView更有意义呢?
viewDidLoad中
self.pageViewController = self.storyboard?.instantiateViewControllerWithIdentifier("QuizPageViewController") as! UIPageViewController
self.pageViewController.dataSource = self
let startVC = self.viewControllerAtIndex(0) as QuestionViewController
let viewControllers = NSArray(object: startVC)
self.pageViewController.setViewControllers(viewControllers as? [UIViewController], direction: .Forward, animated: true, completion: nil)
self.pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.size.height)
self.addChildViewController(self.pageViewController)
self.view.addSubview(self.pageViewController.view)
self.pageViewController.didMoveToParentViewController(self)
PageViewController委托
func viewControllerAtIndex(index: Int) -> QuestionViewController
{
if ((self.pageTitles.count == 0) || (index >= self.pageTitles.count)) {
return QuestionViewController()
}
let vc: QuestionViewController = self.storyboard?.instantiateViewControllerWithIdentifier("QuestionViewController") as! QuestionViewController
vc.questionText = self.pageTitles[index] as! String
vc.pageIndex = index
vc.pageCount = self.pageTitles.count
return vc
}
func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController?
{
let vc = viewController as! QuestionViewController
var index = vc.pageIndex as Int
if (index == 0 || index == NSNotFound)
{
return nil
}
index--
return self.viewControllerAtIndex(index)
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController? {
let vc = viewController as! QuestionViewController
var index = vc.pageIndex as Int
print(index)
if (index == NSNotFound)
{
return nil
}
index++
if (index == self.pageTitles.count)
{
return nil
}
return self.viewControllerAtIndex(index)
}
func presentationIndexForPageViewController(pageViewController: UIPageViewController) -> Int
{
return 0
}