CollectionView move to next cell automatically swift

后端 未结 11 2206
耶瑟儿~
耶瑟儿~ 2021-01-31 21:05

I am trying to create horizontal slider like Flipkart. I am using collectionView with Horizontal scrolling and paging. Cell contains imageView. I am succeed in scrolling items h

11条回答
  •  悲&欢浪女
    2021-01-31 21:29

    Use your pagecontrol property and scrolltoitem.
    
    func setuptimer() {
      timer = Timer.scheduledTimer(timeInterval: 3, target: self , selector: 
    #selector(startScrolling), userInfo: nil, repeats: true)
    
    }
    
    @objc func startScrolling() {
    
        if pageControl.currentPage == pageControl.numberOfPages - 1 {
            pageControl.currentPage = 0
        } else {
        pageControl.currentPage += 1
        }
        .scrollToItem(at: IndexPath(row: pageControl.currentPage, section: 0), at: .right, animated: true)
    }
    

提交回复
热议问题