2016-08-23 415 views
0

你好,我有UIControllerView,我設置UIEdgeInsets下面的代碼;如何設置UICollectionView填充UIEdgeInsets

self.automaticallyAdjustsScrollViewInsets = false 
    self.collectionView.contentInset = UIEdgeInsets(top: 10, left: 10, bottom: 100, right: 10) 

我的內容查看代碼

let contentWidth = maxWidthInASection 
    let contentHeight = Double(collectionView!.numberOfSections()) 
    self.contentSize = CGSize(width: Double(contentWidth), height: contentHeight) 
    self.contentSize.height = CGFloat(Double(collectionView!.numberOfSections())) 

但是行不通用戶didnt選擇底部cells所以當用戶滾動自動轉到我需要添加底部填充大小50- 100 px像空區下側的細胞。

第二個是;

當用戶在收集視圖後滾動收集視圖單元格首先打開位置我想禁用它,如果用戶觸摸並移動集合視圖任何地方都必須停留在那裏不要去第一個位置?根據下文

我的樣品圖片的底部填充

enter image description here

我該怎麼辦呢?

謝謝!

+0

您將擁有一個集合視圖委託方法 - collectionView:didEndDisplayingCell:forItemAtIndexPath :.在這裏找到它是否是最後一個indexPath。如果是,那麼你可以增加collectionView或scrollViews的高度或修改contentSize。 – user3300864

+0

您還可以添加項目數量作爲requiredItemCount + 10.因此將創建額外的行。但是在itemAtIndexPath裏面你可以檢查indexPath是否小於requiredItemCount然後返回單元格。否則返回零。 – user3300864

+0

@ user3300864我添加了contentview代碼也許需要改變他們你可以看到我的問題 – SwiftDeveloper

回答

1
let flow: UICollectionViewFlowLayout = CollectionView.collectionViewLayout as! UICollectionViewFlowLayout 
    flow.sectionInset = UIEdgeInsetsMake(70, 0, 0, 0) 
+0

我添加contentview代碼也許需要改變他們你的代碼不工作 – SwiftDeveloper

1

你應該計算高度。對於更大的屏幕,更多可以看到。所以它不會自動執行。