Re: UIImageView Scaling
Follow-up. Filed rdar:\\42735829
Image Scaling When Returning From UIImagePickerController
Created on July 30 2018, 12:01 PM for iOS + SDK
UIKit Summary: I have a UIImageView in a scene and call UIImagePickerController to select an image to display in it. In the UIImagePickerControllerDelegate:didFinishPickingMediaWithInfo() function, I load the new image and call SizeToFit(). Depending on implementation details, the displayed image might be correctly sized to fit or may be displayed at full size (as if contentMode were topLeft). Steps to Reproduce: Run the enclosed test application. It includes three cases. In the test app, cases 1 and 3 behave as expected, case 2 shows the incorrect scaling. In may actual app, case 1 also shows incorrect scaling. Expected Results: I expect the image to be scaled to fit in all cases. Actual Results: In some cases, the image is scaled; in others it is not. Please note that opening the scene (when an image exists) ALWAYS displays it correctly. The loadData() method only fails when being called from UIImagePickerController's didFinish... method. THIS LOOKS LIKE A TIMING ISSUE TO ME. WORKAROUND: in LoadImage(), follow imageView.scaleToFit() with imageView.superView!.setNeedsLayout(). IF THIS IS DEEMED CORRECT BEHAVIOR, THEN YOU NEED TO UPDATE DOCUMENTATION. Version/Build: Xcode 9.4.1 and 10.0, iOS 10.3, 11.x, 12.0 Configuration: Tested mainly on a real iPad Air 2 (11.4). Results in Simulator are inconclusive, particularly when using the standard images include in the default Camera Roll (which aren't big enough to show this problem clearly).
July 30 2018, 12:01 PM