我有一个 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)
}
最佳答案
如果scrollView和collectionView的frame是一样的,那么区分调用哪一个肯定是个问题。可能这就是为什么它会导致 collectionView 出现问题。
关于ios - UIScrollView 上的 UICollectionView 卡住,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39100131/