iOS UIScrollView with UIImageView rotation aspect problem
I apologize in advance for my lack of iOS SDK knowledge, I am an Android developer that has been tasked with maintaining and updating an iPhone application.
I am using a UIScrollView to handle zooming and dragging of an image that is being displayed on a UIImageView.
The image in the UIImageView is requested from a web server multiple times a second. When the orientation of the device changes the image dimensions change to that of the current frame, for example when using an iPad in portrait mode the image dimensions will be 768x1024 but when switching to landscape mode the dimensions of the image will be 1024x768. The webserver does the work of adding black bars to the top/bottom or left/right of the image depending on the orientation and aspect ratio of the image I am requesting.
My problem is that after rotating the device the UIImageView never behaves the way I expect it to. My expected behavior is that the UIScrollView will continue to perform its scrolling actions but reset its base view to that of the new frame dimensions after rotation.
If I don't specify a contentMode for the UIScrollView then the Image appears squished as though the ScrollView is trying to display the image in the previous orientations dimensions.
If I spe开发者_开发知识库cify a contentMode of UIViewContentModeScaleAspectFit for the ScrollView and zoom all the way out the image appears smaller than the View, the aspect ratio is correct, but the image is centered and the height is that of the previous orientations.
If I specify a contentMode of UIViewContentModeScaleAspectFill for the ScrollView everything appears correctly, but since the View is actually scaling the image up to fit the screen when I exit the scrollView the zoom data that I was using doesn't properly translate over.
What do I need to do to set the "base size" of the UIScrollView to the new frame size when the device orientation has changed? Or am I missing a property that I need to have set?
It sounds like you may not be updating the content size on the scroll view. You need to do something like
scrollView.contentSize = newImageSize;
Hope that's it
If I understand correctly, you can use the zoomToRect:animated:
method in UIScrollView. You can then set the zoom to the size of the image.
精彩评论