gpt4 book ai didi

ios - 在 UIViewController 前面添加 am UIPageViewController

转载 作者:行者123 更新时间:2023-11-28 07:05:56 26 4
gpt4 key购买 nike

当我的应用程序第一次启动时,它应该在第一个应用程序屏幕前面显示一个教程,这是一些具有半透明背景的屏幕。

我尝试创建一个 UIPageViewController 对象,将其 View 添加为当前屏幕的 subview (self.view.addSubview(tutorialViewController.view)) 并显示屏幕,但是当我滑动 UIPageViewController 没有响应事件。

class TutorialViewController:UIPageViewController, UIPageViewControllerDataSource {
var tutorialsViewControllers = [UIViewController]()


override func viewDidLoad() {
super.viewDidLoad()
tutorialsViewControllers.append(Tutorial1ViewController())
tutorialsViewControllers.append(Tutorial2ViewController())
tutorialsViewControllers.append(Tutorial3ViewController())
tutorialsViewControllers.append(Tutorial4ViewController())
tutorialsViewControllers.append(Tutorial5ViewController())
self.setViewControllers([tutorialsViewControllers.first!], direction: .Forward, animated: false) { (complete) -> Void in
}
self.dataSource = self
}

func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -> UIViewController? {
if let position = find(self.tutorialsViewControllers, viewController)
where position > 0
{
return self.tutorialsViewControllers[position - 1]
}
return nil
}
func pageViewController(pageViewController: UIPageViewController, viewControllerAfterViewController viewController: UIViewController) -> UIViewController?{
if let position = find(self.tutorialsViewControllers, viewController)
where position < self.tutorialsViewControllers.count - 1
{
return self.tutorialsViewControllers[position - 1]
}
return nil
}
}

这是 View Controller 代码

let tutorialViewController = TutorialViewController()        
self.view.addSubview(tutorialViewController.view)

最佳答案

您是否将 tutorialViewController 添加为 subview Controller ?

self.addChildViewController(tutorialViewController)
self.view.addSubview(tutorialViewController.view)

关于ios - 在 UIViewController 前面添加 am UIPageViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30640154/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com