Re: UIImageView Scaling


Steve Christensen <punster@...>
 

Questions:

1. Do you get different sizing behavior for the same image depending on which case/path gets taken?

2. How does the UIImageView size compare with image.size for the misbehaving case?


On Jul 20, 2018, at 1:35 PM, Rick Aurbach via Groups.Io <rlaurb@...> wrote:

I have a UIImageView, which I load with the following function:

func loadData() {

guard let recipe = recipe,

let fileN = recipe.photo,

!fileN.isEmpty else {

imageView.image = nil

xableTrashButton()

return

}

let filePath = ImageUtils.fileURL(fileName: fileN, directory: .applicationSupportDirectory)!.path

imageView.image = UIImage(contentsOfFile: filePath)

imageView.contentMode = .scaleAspectFit

imageView.sizeToFit()

xableTrashButton()

}


I create a new image using a standard UIImagePickerController. In its imagePickerController(_ picker:didFinishPickingMediaWithInfo info:) delegate method, I save the image to a file (in the .applicationSupportDirectory) and save the image name in my database. Then I dismiss the pickerController, and call the above loadData() method in it's completion handler.

I observe two cases. In all cases except the above "exit from picker" case, the image is shown scaled to fit in the UIImageView. But in the case of "exit from picker", the upper left corner of the image is shown in the UIImageView at its full size.

Does anyone have any idea what might be happening here? And what I can do to get the (desired) effect of displaying the image scaled to its imageView in all cases?

Thanks,

Rick Aurbach

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