Re: UIImageView Scaling


Rick Aurbach
 

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.

Yup. It disturbs me too.

But unless UIImagePickerController is doing something funky behind the scenes, then no, I am not doing anything on a background thread, nor am I explicitly making any changes to layout except for setting imageView.image and calling imageView.sizeToFit().

In fact, I’ve tried calling my loadData() method from
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { [weak self] in 
self?.loadData()
}

and it doesn’t help.

What it “feels like” (whatever that means) is that there is some race condition or timing condition between code being executed in the UIImagePickerControllerDelegate’s done-handler and the layout/display subsystem for the imageView in the presenter’s view scene.

If you’re inclined to play with this, I put a sample app together yesterday afternoon. https://www.dropbox.com/s/avx6y6kkb9mpwhh/ImageViewScaling.zip?dl=0
Please note that Case #1 appears to work in the Sample App, but not in my real app. I’m currently using Case #3 in my real app. Case #2 fails in both places.

Cheers,

Rick

Join {cocoa@apple-dev.groups.io to automatically receive all group messages.