iOS collecitonVIewCell 滑动到屏幕中央
// 获取当前cell的frame
let att = self.collectionView.layoutAttributesForItem(at: IndexPath(row: index, section: 0))!
// 计算出偏移量,当前cell的中心点x
let offset = CGPoint(x: att.frame.origin.x-LCXScreenWidth/2+att.bounds.width/2, y: 0)
self.collectionView.setContentOffset(offset, animated: true)
iOS collecitonView 获取某一个cell经过某个位置
func scrollViewDidScroll(_ scrollView: UIScrollView) {
/// 获取collecitonView头部的中点
let point = self.collectionView.superview!.convert(CGPoint(x: scrollView.center.x, y: 0), to: self.collectionView)
// 转换成经过此处的index
if let index = self.collectionView.indexPathForItem(at: point){
}
}
网友评论