sochalewski / UIImageViewAlignedSwift

A UIImageView subclass which allows you to align the image left/right/top/bottom, even when contentMode is AspectFit. Swift now.
MIT License
236 stars 67 forks source link

Image duplication in iOS 13b3 [BUG] #25

Closed yuriandryu closed 4 years ago

yuriandryu commented 5 years ago

I have the same problem! If the image is aligned, 2 images appear, one aligned and the second in the center of the original. Please pack it as soon as possible!

awedeebawe commented 5 years ago

Instead of complaining, try to fix it yourself ;)

yuriandryu commented 5 years ago

I tried, it didn’t work. I don’t have one problem, please solve this problem as soon as possible.

awedeebawe commented 5 years ago

@yuriandryu I forked the repo, then replaced the superclass to UIView. Removed the override-s and the calls for super.image and basically fixed the errors in the class. Yes, I lost the ability to attach Kingfisher to that UIImageView, or the RxCocoa .rx.image property, but still, it works now.

yuriandryu commented 5 years ago

I respect. did as you said, everything works now! Thanks bro

neilkachu commented 5 years ago

Rather than remove kf etc UIImageView support I worked around this by ensuring the super image wasn't one that can be seen. So I updated updateLayout to set the super image to a transparent image like so; works fine for now.

if #available(iOS 11, *) { super.image = UIImage(named: "transparent_image") }

CRoig commented 5 years ago

@neilkachu Tried your solution unsuccessfully 😢. Is transparent_image just a place holder, or it is an actual existing transparent image? this is suppose to replace the = nil.

tomspee commented 5 years ago

@neilkachu Your solution doesn't work for me unfortunately. I have a transparent asset but still double images.

christoff-1992 commented 5 years ago

Im not sure if its a bug, I would have thought that setting the layers contents to nil should in theory remove the image however setting the layers contents to a CALayer works fine. e.g.

if #available(iOS 13, *) {
   self.layer.contents = CALayer()
} else if #available(iOS 11, *) {
   super.image = nil
} else {
   layer.contents = nil
}
neilkachu commented 5 years ago

@neilkachu Tried your solution unsuccessfully 😢. Is transparent_image just a place holder, or it is an actual existing transparent image? this is suppose to replace the = nil.

Yes, just a 1px transparent image in the Assets lib so not sure why it's not working your end, that was the only change I ended up with., @christoff-1992 's solution looks cleaner, I'd re-try with that.

skyparentile commented 4 years ago

Fixed removing if #available(iOS 11, *) { super.image = nil }

everywhere (didMoveToSuperview,didMoveToWindow,updatelayout, etc)

This fix also for iOS11.

You need only to invalidate layer: layer.contents = nil