Very confusing implementation of the .ScaleAspectFit behaviour. This could be more lucid.
if (subview.isKindOfClass(UIImageView)) {
if let image = imageView.image {
if (imageView.contentMode == .ScaleAspectFit) {
if (image.size.width > imageView.frame.size.width || image.size.height > imageView.frame.size.height) {
if (image.size.width < image.size.height) {
// Landscape format
if (ratioWidth > imageView.frame.size.width) {
// Portrait does not fit into subview:UIImageView
} else {
// Portrait fits into subview:UIImageView
}
} else {
// Portrait format
if (ratioHeight > imageView.frame.size.height) {
// Landscape does not fit into subview:UIImageView
} else {
// Landscape fits into subview:UIImageView
}
}
} else {
// Image is smaller than subview:UIImageView
}
} else {
// contentMode is not .ScaleAspectFit
}
}
}
Very confusing implementation of the .ScaleAspectFit behaviour. This could be more lucid.