0

It's the same question with Simon's

But i can't comment there because of 50 reputation and i have the exact same problem. Sorry for re-post but there was no solution. Any help is appreciated. Thanks!

The Problem is..

I have a

-UIScrollView

---Labels

---Labels

---UICollectionView

I have disabled the UICollectionViews scrolling functionality, so I only want to scroll with the Scrollview. My problem is that I don't know how I can calculate the UICollectionViews height so I can update my UIScrollView. If it's many elements inside the UICollectionView, it's get clipped.

I have created this little HTML example to show what I'm looking for http://jsfiddle.net/hDwPH/

Dummy

2 Answers 2

1

I suggest to to let it just one collectionView instead of creating this view hierarchy, it is not a good practice to add a scrollview inside another scrollview.

When implementing cellForItemAtIndexPath, you can check what's the current indexPath.item, based on it -let's say if it 0 or 1-, you can return a different custom cell that contains your the label(s).

For example:

Swift 2

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    // check depends on how many cells they should be to display the labels, i.e: one label for each cell or all of the labels in one cell:
    if indexPath.item == 0 {
        // retrun the cell with the label(s)
    }

    // return the regular cell...
}
Sign up to request clarification or add additional context in comments.

Comments

0

It's better to use single CollectionView with different kind of cells.

But if you need to use it as you described, you should change contentSize of UIScrollView. And frame of collectionView(or height constraint if you use automatic layout). But it's a dirty way

collectionView.reloadData()
collectionView.layoutIfNeeded()
scrollview.contentSize.height = labelsHeight + collectionView.contentSize.height
collectionView.frame.size.height =     collectionView.contentSize.height

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.