0
votes

I have an UIViewController, which contains UIScrollView, which contains a few elements, including UICollectionView. UICollectionView is used to display N buttons in fixed frame. UICollectionView scrolling is disabled. Still, my UIScrollView scrolls not as smoothly as it scrolls without UICollectionView. What my be the problem? Does it have something to do with reusable cells?

code:

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)
}
1

1 Answers

0
votes

If the frame of the scrollView and collectionView is same then it must be a problem to differentiate, which one to call. May be that is why it's creating an issue with the collectionView.