iOS 11 beta UICollectionViewCell resizes as it approaches top bar using contentInsetAdjustmentBehavior
Asked Answered
C

3

6

My app has a UIViewController with a container view that fills the entire screen. The container view embeds a UICollectionViewController. These view controllers should scroll under and show through below the status bar. In order to achieve this, I've set the UICollectionViewController.contentInsetAdjustmentBehavior = .never. As I scroll the collectionview and the top of cells scroll under the status bar, the contents of the cell shrink. This is incorrect. I just want them to scroll under the status bar as they did in iOS 10.3.

I have developed a small test app that exhibits my bug and uploaded it as a bug report. It looks so broken that I can't imagine how others haven't see the same issue.

Small test project here: https://github.com/murthyveda2000/ios11bug

Cm answered 25/7, 2017 at 22:5 Comment(4)
I have experienced this issue as well. @vm2000, have you come across a solution?Aldric
I submitted a bug report to Apple over a month ago. They seem to acknowledge that it is a bug but have not proposed a solution yet.Cm
Hey @vm2000, can you please post a link to that bug so I can track it as well?Aldric
Sure. I don't know if it is visible to people other than me, but here is the link: bugreport.apple.com/web/?problemID=33522000Cm
R
9

This feels like a total hack, and I hope this is actually a bug that Apple will fix (but I'm seeing it in the Xcode 9 GM so I'm less optimistic) but I was able to fix this on your sample project with:

cell.contentView.insetsLayoutMarginsFromSafeArea = false

In an app with more complex layouts, I've also had to apply this to subviews that use layout margin guides.

This probably has unintended consequences and will look like a very bad answer in a week. I suspect if you support rotation, this might screw things up.

Roseliaroselin answered 12/9, 2017 at 21:27 Comment(1)
That works great! It fixes the sample project but it also fixes my app which has quite complicated layouts and supports rotation. I had found some other workarounds where I left contentInsetAdjustmentBehavior = .automatic but then had to do a bunch of other work arounds to adjust the layout myself. This is a MUCH cleaner and simpler solution. Assuming Apple doesn't fix this bug, I'll be using this. Thanks!Cm
C
0

In case anyone else is searching, you can also achieve this from within a Storyboard by unchecking Safe Area Relative Margins from the Size Inspector of the selected view in question.

Screenshot of the Safe Area Relative Margins setting in Storyboard

Cata answered 21/10, 2017 at 22:17 Comment(0)
P
0

I had the same issue and figured it out based on your sample.

Probably during constraints creation you put top constraint to top with margin. All you need to do is uncheck Relative to margin for the top constraint of the ImageView and everything should work fine.

Screenshot here: https://i.sstatic.net/f4hsu.png

Don't forget to change Min spacing For Lines in your collection view to see even the bottom space under items.

Posehn answered 16/6, 2022 at 16:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.