2016-12-28 67 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

它爲我工作。 –

相關問題