Haneke / HanekeSwift

A lightweight generic cache for iOS written in Swift with extra love for images.
Apache License 2.0
5.2k stars 591 forks source link

Crash when setting image for zero sized Image View #145

Open sharpfive opened 9 years ago

sharpfive commented 9 years ago

Crash happens after the downloading an image for the first time.

logoImage.frame = CGRectZero logoImage.hnk_setImageFromURL(logoImageURL)

Crash happens in: Haneke.ImageResizer.resizeImage

Subsequent calls to set_ImageFromURL do not crash if the image has been downloaded and resized previously.

Installed via Carthage github "Haneke/HanekeSwift" "v0.8.1"

sharpfive commented 9 years ago

There are explicit asserts in the resizing code.

Format.resizeImage

TosinAF commented 9 years ago

We have to set the scale mode to none, but I cant seem to find out how to.

tovkal commented 9 years ago

Read hpique response on #95. I was able to get it working with imageView.setImageFromURL(URL, format: Format<UIImage>("original")), but when trying to use the closure to resize (the first example) I got some error I can't remember now.

andreyrd commented 8 years ago

Why does it have to do an assert by default, causing the app the crash? Why not fall back to loading the full sized image? In my opinion, this shouldn't be a fatal error. I ended up writing an extension that falls back to full size if the image view has a zero size:

import Haneke
import UIKit

extension UIImageView {
    func hnk_setImageFromURLAutoSize(url: NSURL) {
        var format: Format<UIImage>? = nil
        if frame.size == CGSize.zero {
            format = Format<UIImage>(name: "original")
        }
        hnk_setImageFromURL(url, format: format)
    }
}