2015-12-22 27 views
0

enter image description hereminimumInteritemSpacingForSectionAtIndex爲UICollectionViewCell是不正確

上面的圖片顯示4個細胞的中心。正如你所看到的,minimumInteritemSpacingForSectionAtIndex和minimumLineSpacingForSectionAtIndex是不一樣的。我已經設置展位細胞和線路爲1

這裏是我的單元佈局代碼:謝謝

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { 

     //Get device resolution 
    screenSize = UIScreen.mainScreen().bounds 
    screenWidth = screenSize.width 
    screenHeight = screenSize.height 

     let screenWidth = screenSize.width 

     let size = CGSize(width: screenWidth/2 , height: 500) 
     return size 
    } 

    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets { 
     return UIEdgeInsetsMake(0, 0, 10, 0); 
    } 

    func collectionView(collectionView: UICollectionView, 
     layout collectionViewLayout: UICollectionViewLayout, 
     minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat { 
      return 1.0 
    } 

    func collectionView(collectionView: UICollectionView, layout 
     collectionViewLayout: UICollectionViewLayout, 
     minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat { 
      return 1.0 
    } 

PS:截圖是iPhone 6模擬器。對於iPhone 6加上間距似乎是正確的。

回答

0

請注意,它被稱爲minimumInteritemSpacing而不是interitemSpacing。這意味着間距不會小於1.0,但可能會超過1.0。

至於你的情況,你可以嘗試調整sizeForItemAtIndexPath,返回一個寬度等於(screenWidth - 1.0)/2,使interitemSpacing剛好1.0。