0

I want a CollectionView to arrange under a TextView without gap.

I'm programmatically creating the TextView, attaching this to TopLayoutGuide.bottomAnchor and attach the topAnchor of an existing CollectionView to the bottom of the TextView.

collectionView.topAnchor.constraint(equalTo:textView.bottomAnchor).isActive = true

Using this line, it works fine on - I assume - every simulator. But on a physical device (iPhone 5 right now), the CollectionView has a gap to the textview. The gap is maybe the height of the textview.

enter image description here

If I change the constraint to attaching the CollectionView to the topLayoutGuide.bottomAnchor - which is nonsense - its exactly the opposite behaviour. Than the gap is in the simulator and not on the device.

collectionView.topAnchor.constraint(equalTo:self.topLayoutGuide.bottomAnchor).isActive = true

Added image of debugging the views:

enter image description here

What am I doing wrong?

Max Power
  • 169
  • 10
  • The simulator and device are the same model and iOS version?? – Yitzchak Nov 29 '17 at 15:57
  • It's an physical iPhone 5 (latest 10.3.3) and an iPhone 5 simulator (10.3.1). But I tried several simulators with different versions, latest too, without differences. – Max Power Nov 29 '17 at 18:03
  • I believe you should set the **headerReferenceSize** of your **UICollectionViewFlowLayout**. You can do it in code, or interface builder, choose what better suites you – Yitzchak Nov 29 '17 at 18:33
  • did my suggestion helped you? – Yitzchak Nov 29 '17 at 21:32
  • Thank you but it doesnt help. This value is zero by default if not set. I tried setting the headerRefSize to -50. It shifts up, but on both iOS. Then it's overlapping the navigationBar on the physical device. – Max Power Nov 30 '17 at 09:49
  • There is a button in the debugger that shows you all views and their size and position. Use it! See this: https://stackoverflow.com/a/26052806/2830676 – Yitzchak Nov 30 '17 at 12:11
  • See my updated post. The collectionView is indeed pinned to the textView. The gap is within the collectionView...but the insets of the cell are correct with x: 10 and y: 5. I can't find more. It's just flying there... – Max Power Nov 30 '17 at 18:06
  • I really believe that you find the correct field in the flow layout!! Try there all values to 0 – Yitzchak Nov 30 '17 at 18:09

0 Answers0