借助计时器,Swift 4自动在页面视图控制器中滑动

时间:2018-10-06 07:12:35

标签: ios swift uipageviewcontroller

我正在尝试使用100010000001000000000101000000011 auto sliding中创建page view controller。在这里,我尝试使用下面的代码,但得到结果,它正在重复图像的第一个swift 4。我需要知道,如何实现下一个索引的移动?

index

1 个答案:

答案 0 :(得分:0)

    // Image array
    var name = ["one.png","two.png","three.png","four.png"]
    var currentIndex = -1

    // Timer in viewdidload()
    tTime = Timer.scheduledTimer(timeInterval: 4, target: self, selector: #selector(changeSlide), userInfo: nil, repeats: true)


    // Timer function call
    @objc func changeSlide() 
   {
    currentIndex = (currentIndex == name.count - 1) ? 0 : currentIndex + 1

    let pageContentViewController = self.viewControllerAtIndex(index: currentIndex)
    self.pageViewController.setViewControllers([pageContentViewController!], direction: UIPageViewControllerNavigationDirection.forward, animated: true, completion: nil)
}