ios - UIScrollView 上的 UICollectionView 卡住

标签 ios swift uiscrollview uicollectionview

我有一个 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/

相关文章:

ios - tapGestureRecognizer 在 UIScrollView Swift 上不触发 Action

swift - 当我的奖励视频结束时,它不会给用户硬币.......为什么?

ios - 使滚动条在 UIScrollView (iOS7) 上始终可见?

iphone - UIScrollView 委托(delegate)方法冲突

ios - 与自定义 UITableViewCells 关联的 NSTimers 离开屏幕时无效/停止

ios - 自定义 Tableview 单元格宽度问题

json - 为什么解码后的 json nil 使用 Codable?

iOS NSDate() 返回错误的时间

iphone - 如何在iPhone应用程序中使用两位小数获取字符串

iphone - NSMutableArray具有相同的引用