【发布时间】:2016-12-30 05:17:56
【问题描述】:
我有一个 UIViewController,它包含 UIScrollView,其中包含一些元素,包括 UICollectionView。 UICollectionView 用于在固定框架中显示 N 个按钮。 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)
}
【问题讨论】:
标签: ios swift uiscrollview uicollectionview