简体   繁体   中英

how to know the positioning of collectionview cell on the device screen

hi i am new to the ios development, I am using collectionview that shows one cell at a time and scrolls horizontally (like a gallery), what I am trying to do is to change the labels present on my screen when the cells are being scrolled and cell 0 and cell 1 are being displayed on the screen half-half. Currently the text in labels change when the scrolling gets stopped. I am using func scrollViewDidEndDecelerating(_ scrollView: UIScrollView)

Edit 1:

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    let visibleRect = CGRect(origin: imageCollectionView.contentOffset, size: (imageCollectionView.bounds.size))
    let visiblePoint = CGPoint(x: visibleRect.midX, y: visibleRect.midY)
    let indexPath : IndexPath = imageCollectionView.indexPathForItem(at: visiblePoint)!
    lblUserName.text = arrayImageData[indexPath.row]["userName"] as! String?
    lblTime.text = arrayImageData[indexPath.row]["time"] as! String?
    imgProfilePic.kf.setImage(with: arrayImageData[indexPath.row]["profilePic"] as! Resource?)
}

您只需要实现scrollViewDidScroll

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM