CollectionView move to next cell automatically swift

后端 未结 11 2281
耶瑟儿~
耶瑟儿~ 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:39

    swift 4:

    func scrollToNextCell(){
    
        //get cell size
        let cellSize = view.frame.size
    
        //get current content Offset of the Collection view
        let contentOffset = collectionView.contentOffset
    
        if collectionView.contentSize.width <= collectionView.contentOffset.x + cellSize.width
        {
            let r = CGRect(x: 0, y: contentOffset.y, width: cellSize.width, height: cellSize.height)
            collectionView.scrollRectToVisible(r, animated: true)
    
        } else {
            let r = CGRect(x: contentOffset.x + cellSize.width, y: contentOffset.y, width: cellSize.width, height: cellSize.height)
            collectionView.scrollRectToVisible(r, animated: true);
        }
    
    }
    

提交回复
热议问题