2016-12-28 58 views
1

我在视图控制器中使用了UICollectionView并传递了一组图像。我已启用收集视图的分页。但是当我滚动到下一张图像时,以前的单元格不会完全消失。它仍然处于边缘。所以,how I can make only specific image/cell visible while scrolling left/Right.如何在UICollectionView中显示特定单元格的矩形

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 

    if collectionView == collection_LargeView 
    { 
     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Large Cell", for: indexPath)as! LargeImageCell 
     cell.imageView_LargePic.sd_setImage(with: NSURL(string: array[indexPath.row]) as URL!) 
     cellIndex = indexPath 
     return cell 
    } 
    else 
    { 
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Picture Cell", for: indexPath)as! VendorPictureCell 
     cell.imageView_VendorPics.sd_setImage(with: NSURL(string: array[indexPath.row])as URL!) 
     return cell 
    } 
} 

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 


    return array.count 

} 

//当在底部收集视图项目选择了其他集合视图滚动到indexPath

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 
    if collectionView == collectionView_picturesCollection 
    { 
     Index = indexPath.row 
     collection_LargeView.scrollToItem(at: indexPath, at: .right, animated: true) 
    } 

} 

请解决这个问题。 谢谢。

After scrolling from one cell to next Screenshot : https://i.stack.imgur.com/msmnV.jpg

+0

给我集合视图的屏幕截图 –

+0

能否请你在这里更新的代码,你是使用? – SNarula

+0

https://i.stack.imgur.com/msmnV.jpg –

回答

0

你的拳头改变你的故事板的的CollectionView在最小间距为细胞和系0像以下图片:

enter image description here

enter image description here

我希望它可以帮到你

+0

//流布局委托方法 FUNC的CollectionView(_的CollectionView:UICollectionView,布局collectionViewLayout:UICollectionViewLayout, sizeForItemAt indexPath:IndexPath) - > CGSize { 让细胞= collection_LargeView.cellForItem(在:indexPath) 返回CGSize(宽度: (cell?.contentView.frame.size.width)!, height:(cell?.contentView.frame.size.height)!) } –

+0

@Nirav D谢谢 –

+0

@sahil,您是否在xcode中应用了上述内容 –

0

FUNC的CollectionView(_的CollectionView:UICollectionView,布局collectionViewLayout:UICollectionViewLayout,sizeForItemAt indexPath:IndexPath) - > CGSize {

if collectionView == collection_LargeView 
    { 
    return CGSize(width: self.view.frame.size.width, height: 524.0) 
    } 
    else{ 
    return CGSize(width: 86.0, height: 74.0) 
    } 
} 
+0

它为我工作。 –

相关问题