我有自定义UICollectionView
有4个项目和水平滚动。所以3个项目是可见的,还有一个不是。滚动到最后,我想选择last(4)单元格,在此之后 - 我的UICollectionView
视图滚动到0.0 offset
,所以感觉没有选择单元格(4),但在重新注册到最后,我看到它已被选中。我的目标是删除这个奇怪的“autoscroll
”开始。我有自定义布局
let collectionViewLayout = FullyHorizontalFlowLayout()
collectionViewLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
collectionViewLayout.itemSize = CGSizeMake((UIScreen.mainScreen().bounds.width - 60) / 3, (((UIScreen.mainScreen().bounds.width - 60) / 3 ) + 50));
collectionViewLayout.nbColumns = 1;
collectionViewLayout.nbLines = 1;
collectionViewLayout.minimumInteritemSpacing = 0
collectionViewLayout.minimumLineSpacing = 0
collection.collectionViewLayout = collectionViewLayout
collection.pagingEnabled = true
collection.scrollsToTop = false
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
print(self.bottomCollectionView.contentOffset)
if collectionView.tag == 1 {
let indexPath = bottomCollectionView.indexPathsForSelectedItems()?.first
if indexPath != nil {
bottomCollectionView.deselectItemAtIndexPath(indexPath!, animated: false)
}
} else {
let indexPath = self.collectionView.indexPathsForSelectedItems()?.first
if indexPath != nil {
self.collectionView.deselectItemAtIndexPath(indexPath!, animated: false)
}
}
print(self.bottomCollectionView.contentOffset)
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if collectionView.tag == 1 {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell_for_master_pick", forIndexPath: indexPath) as! MasterPickCollectionViewCell
let service = servicesCategoriesArray[indexPath.item]
cell.masterPhotoView.layer.cornerRadius = (UIScreen.mainScreen().bounds.width - 80) / 6
cell.photoOutsideView.layer.cornerRadius = (UIScreen.mainScreen().bounds.width - 80) / 6
print(service.name)
cell.masterNameLabel.text = service.name
cell.masterPhotoView.sd_setImageWithURL(NSURL(string: service.image_url!))
cell.masterPhotoView.backgroundColor = Colors().gBarVioletColor
// cell.layoutIfNeeded()
return cell
} else {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell_for_master_pick", forIndexPath: indexPath) as! MasterPickCollectionViewCell
let service = packagesArray[indexPath.item]
cell.masterPhotoView.layer.cornerRadius = (UIScreen.mainScreen().bounds.width - 80) / 6
cell.photoOutsideView.layer.cornerRadius = (UIScreen.mainScreen().bounds.width - 80) / 6
print(service.name)
cell.masterNameLabel.text = service.name
cell.masterPhotoView.sd_setImageWithURL(NSURL(string: service.image_url!))
cell.masterPhotoView.backgroundColor = Colors().gBarVioletColor
// cell.layoutIfNeeded()
return cell
}