I have a collectionViewCell which displays an image. I have added a scrollView to that cell and storyboard constraints to pin the scrollView to the top, bottom, leading, trailing of superview.
I have then added an imageView in storyboard as a subview of the scrollView and added the similar 4 constraints to the imageView's superview which is the scrollView.
At this stage there is a red warning in storyboard because the scrollView needs constraints for scrollable height and width.
That can be silenced by setting the width and height of the imageView to equal to the cell's containerView. i.e. the superview of the scrollView.
When I run the image displays correctly. However when I zoom in by pinching, there is an awkward margin at the top and bottom of the imageView when I pan around.
I assume this is because the size of the imageView in height is larger than the image so when I zoom, the area above and below the image is also in the contentSize of the scrollView.
The imageView is set to aspectFit.
Not sure what the best way to resolve this is.
Edit 1
Here are two screen shots. I've made the imageView's background view pink to demonstrate what is happening. The first image is the correctly displayed image prior to zooming. In the second image the image is zoomed and panned. I want to eliminate the border at the top when I zoom in.
Edit 2,
I have also tried adding a fixed width and height constraint to the imageView which gets updated when the image is added. Everything works fine in this case except the imageView is positioned at the top left corner of the scrollView and not centered.