Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution to Haneke fails on CGSizeZero UIImageView #317

Closed
drosenstark opened this issue May 24, 2016 · 4 comments
Closed

Solution to Haneke fails on CGSizeZero UIImageView #317

drosenstark opened this issue May 24, 2016 · 4 comments
Labels

Comments

@drosenstark
Copy link

Haneke fails one of its asserts if you try to load using hnk_setImageFromURL when the UIImageView is size zero. This is my hack to deal with this:

class UIImageViewWithDelayedLoad : UIImageView {
    var url : NSURL?

    init(urlForLoadWhenFrameNotZero: NSURL) {
        super.init(frame: CGRectZero)
        self.url = urlForLoadWhenFrameNotZero
    }

    required init?(coder: NSCoder) { super.init(coder: coder) }

    override func layoutSubviews() {
        super.layoutSubviews()

        guard let url = url else { return }
        guard (frame.size.width > 0 && frame.size.height > 0) else { return }
        self.hnk_setImageFromURL(url)
        self.url = nil
    }
}

Is this redundant with some functionality in Haneke? If not, possibly it's useful to somebody else... thanks!

@TosinAF
Copy link

TosinAF commented May 27, 2016

Quick heads up

You can avoid all that with hnk_setImageFromURL(url, format: Format(name: "original"))

Using a standard format disables the resizing that leads to that crash when the imageView has no frame due to autolayout.

@drosenstark
Copy link
Author

thanks!!! so, in your solution which image is cached? in my solution, is it both the original and the resized? thanks for this response!

@TosinAF
Copy link

TosinAF commented May 27, 2016

Happy to help, so basically Format original, caches the original image, no resizing is done.

If you wanted, you could pass in a custom format and the result of that is what is cached.

let iconFormat = Format(name: "icons", diskCapacity: 10 * 1024 * 1024) { image in
return imageByRoundingCornersOfImage(image)
}

@drosenstark
Copy link
Author

So my class, though it was created in ignorance, could kind of make sense to cache the resized image, assuming that the frame gets set and changes to a non-zero size only once?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants