CollectionView move to next cell automatically swift

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

    Below is code you can try :

        /**
         Scroll to Next Cell
         */
        func scrollToNextCell(){
    
            //get Collection View Instance
            let collectionView:UICollectionView;
    
            //get cell size
            let cellSize = CGSizeMake(self.view.frame.width, self.view.frame.height);
    
            //get current content Offset of the Collection view
            let contentOffset = collectionView.contentOffset;
    
            //scroll to next cell
            collectionView.scrollRectToVisible(CGRectMake(contentOffset.x + cellSize.width, contentOffset.y, cellSize.width, cellSize.height), animated: true);
    
    
        }
    
        /**
         Invokes Timer to start Automatic Animation with repeat enabled
         */
        func startTimer() {
    
            let timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: Selector("scrollToNextCell"), userInfo: nil, repeats: true);
    
    
        }
    

提交回复
热议问题