vm2000
vm2000

Reputation: 342

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

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

Upvotes: 6

Views: 1593

Answers (3)

Dominik Petho
Dominik Petho

Reputation: 1

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.

Upvotes: 0

robfeldmann
robfeldmann

Reputation: 151

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

Upvotes: 0

Kevin
Kevin

Reputation: 3131

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.

Upvotes: 9

Related Questions