0
我有一個UIViewController,其中包含UIScrollView,它包含一些元素,包括UICollectionView。 UICollectionView用於在固定幀中顯示N個按鈕。 UICollectionView滾動被禁用。儘管如此,我的UIScrollView不像UICollectionView那樣滾動。我的問題是什麼?它與可重複使用的單元格有關嗎?UIScrollView UICollectionView凍結
代碼:
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 9
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("tagsCell", forIndexPath: indexPath) as! TagsCollectionViewCell
cell.backgroundColor = UIColor.clearColor()
cell.tagsButton.setTitle("Test", forState: .Normal)
cell.tagsButton.sizeToFit()
return cell
}
func collectionView(collectionView: UICollectionView!, layout collectionViewLayout: UICollectionViewLayout!,
sizeForItemAtIndexPath indexPath: NSIndexPath!) -> CGSize
{
let element = "Test" as NSString
let stringSize = element.sizeWithAttributes([NSFontAttributeName: UIFont.systemFontOfSize(17.0)])
return CGSize(width: stringSize.width + 25, height: 29)
}
滾動視圖的高度大約是1000,而集合視圖是150,寬度是一樣的 – JuicyFruit
那麼它不會產生問題。你能發佈整個代碼嗎?以上只適用於collectionView。 –
你有沒有設置scrollView contentSize的屬性。 –