Re: UIImageView Scaling

Steve Christensen <punster@...>

No worries about disagreements: you're looking at the code and I'm getting the condensed version in your description.

Your comment about timing being an issue disturbs me since, ideally, the behavior should be consistent irrespective of "timing" since everything is funneled through a single thread. Assuming that one of your paths isn't accidentally setting imageView.image on a background thread, are you making any layout adjustments in -viewWillLayoutSubviews, for example? I have had problems where, ultimately, it was my fault but it took a long time to figure out that I was effectively trying to position something at the wrong time.

On Jul 23, 2018, at 8:13 AM, Rick Aurbach via Groups.Io <rlaurb@...> wrote:


I don’t want to disagree with you, but I’m seeing additional pieces of evidence which suggest (to me, at any rate) that this issue is related to timing, not insufficient constraints. I’ll try to explain. (I know a sample app would be best, but I haven’t had time yet to build it. When I do, I’ll post it here.)

(1) First of all, is the important observation that the ONLY time the image is drawn unscaled is when returning from UIImagePickerController. That is, if I visit the scene with the ImageView at any other time, the image appears scaled to the ImageView. It is only when first picking the image and populating the ImageVIew for the first time with the new image that it appears unscaled.

Let me be a bit more explicit about that. The only time the image is drawn unscaled in the ImageView is when performing the following sequence:
  • User selects to put a new image in the image view. 
  • We display the appropriate UIImagePickerController. 
  • The user makes the selection and clicks Done.
  • The picker delegate’s didFinishPickingMediaWithInfo handler is called.
  • In that handler, we explicitly dismiss the picker controller.
  • In the dismiss function’s completion handler, we load the newly selected image into the ImageView (using exactly the same logic as we do when displaying the scene originally).
  • In this case (and this case only), the image in the ImageView is displayed unscaled. 

(2) Originally, the ImageView sat bare in the (sub)-controller’s view. I also tried embedding the ImageView in a ScrollView. In this case, I bound the scrollView to its enclosures Safe Area, then bound the ImageView to the ScrollView and added the “equal height” and “equal width” constraints between ImageView and its enclosing ScrollView. [The ScrollView was not enabled for zoom.] This made no change in behavior.

(3) My imageView is built with a tap gesture recognizer. Tapping the image causes a new window to be presented (in overFullScreen mode), providing pan/zoom support. So I changed the code so that, when dismissing the UIImagePickerController, I first load data into the ImageView, then IMMEDIATELY present this other (covering) window. And when I close this window (thereby revealing the ImageView once again), the image is properly scaled. [I am, in fact, using this approach as a temporary workaround in my latest field-test release. If you’d like to see things in action, please email me privately and I’ll add you to the field test.]

Sorry if this is a bit muddy. It’s much harder to write about than to understand with even a brief glimpse at the code. That’s why I’ll try to generate a sample app.

Hope this helps.



Join { to automatically receive all group messages.