0
votes

In my collection view one of my cells has a UIImageView who's UIViewContentMode is UIViewContentModeScaleAspectFit.

The UIImageView has constraints that resize it's frame on orientation change.

Most of the time everything works wonderfully. But every once in a while the UIImage is cropped when rotated. It seems to have something to do with the reuse (dequeueReusableCellWithReuseIdentifier) as it only happens after a reuse.

In my prepareForReuse I am setting the constraints as they are in my xib.

I have tried setNeedsDisplay. Anyone have any suggestions?

1
Not sure if you've done this yet, but I would suggest looking at the section titled How to set auto layout breakpoint in Xcode debugger in this post: staxmanade.com/2015/06/debugging-ios-autolayout-issues If you can "catch" it when it happens, it might help eliminate some variables re: where problem lives.Adrian

1 Answers

1
votes

I've run into a very similar issue. A collectionView with the cell defined in a xib. The cell has a view that contains UIImageView, which sets width constraint based on orientation mode. It turned out that - contentMode set on the UIImageView was being changed underneath. I would suggest take a look at contentMode and ensure that it is set appropriately (see reference) - either either ScaleAspectFit or ScaleAspectFill