页面视图控制器选择索引到特定视图控制器



我有pageViewcontroller,它会自动从一个页面滑动到另一个页面。

当我点击特定页面时,我想转到另一个视图控制器,我见过许多在幻灯片中显示优惠的应用程序,当我们单击幻灯片索引时,它将转到特定页面。

只需在UIPageControl上添加以下内容:

pageControl.addTarget(self, action: #selector(pageChanged(_:)), for: .valueChanged)

然后赶上事件:

@objc func pageChanged(_ sender: UIPageControl) {
    // Go to the appropriate controller
    let controllerToDisplay = UIViewController() // pick the appropriate controller here
    self.setViewControllers([controllerToDisplay], direction: .forward, animated: true, completion: nil)
}

最新更新