入职按钮不起作用

问题描述 投票:0回答:0

我已经使用 collectionView 创建了一个入职,当我滑动到一侧时页面发生变化但是按钮工作正常,我看到项目的索引正在发生变化,并且页面控件也在工作但幻灯片或当前页面视觉上没有变化。当我按下下一步按钮时,我应该怎么做才能使当前页面发生变化? 这是一个 gitHub 链接:https://github.com/rustinwilde/Onboarding.git

这是一个代码:

var currentPage = 0 {
    didSet {
        pageControl.currentPage = currentPage
        if currentPage == slides.count - 1 {
            nextBtn.setTitle("Got It!", for: .normal)
            nextBtn.backgroundColor = UIColor(red: 51/255, green: 178/255, blue: 73/255, alpha: 1.0)
        } else {
            nextBtn.setTitle("Next", for: .normal)
            nextBtn.backgroundColor = .systemBlue
        }
    }
}

    @IBAction func nextBtnClicked(_ sender: UIButton) {
    pageControl.currentPage = currentPage

    if currentPage == slides.count - 1 {
    print("Go to the next screen")  
    } else {
    nextBtn.setTitle("Next", for: .normal)
    nextBtn.backgroundColor = .systemBlue
    currentPage += 1
    let indexPath = IndexPath(item: currentPage, section: 0)
    collectionView.scrollToItem(at: indexPath, at: .centeredHorizontally,
    animated: true)
        print("SLIDES: \(slides.count)")
        print("CURRENT PAGE \(currentPage)")
        print("indexPath \(indexPath.item)")
    }
}

    func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    let width = scrollView.frame.width
    currentPage = Int(scrollView.contentOffset.x / width)
   
    
    print(currentPage)
    
    }
swift xcode uicollectionview uibutton uipagecontrol
© www.soinside.com 2019 - 2024. All rights reserved.