From 919febb0889e1abf050e7a762cb60720ae23a5c9 Mon Sep 17 00:00:00 2001 From: Dragomir Ivanov Date: Fri, 1 Nov 2019 10:47:32 +0200 Subject: [PATCH 1/5] Fixed duplicate image in iOS 13 --- UIImageViewAligned.swift | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/UIImageViewAligned.swift b/UIImageViewAligned.swift index 3df8c92..bfbb749 100644 --- a/UIImageViewAligned.swift +++ b/UIImageViewAligned.swift @@ -195,17 +195,19 @@ open class UIImageViewAligned: UIImageView { open override func didMoveToSuperview() { super.didMoveToSuperview() - layer.contents = nil + invalidateContents() } open override func didMoveToWindow() { super.didMoveToWindow() - layer.contents = nil + if #available(iOS 11, *) { let currentImage = realImageView?.image image = nil realImageView?.image = currentImage } + + invalidateContents() } private func setup(image: UIImage? = nil, highlightedImage: UIImage? = nil) { @@ -235,11 +237,16 @@ open class UIImageViewAligned: UIImageView { } realImageView?.frame = realFrame.integral - - // Make sure we clear the contents of this container layer, since it refreshes from the image property once in a while. - layer.contents = nil - if #available(iOS 11, *) { - super.image = nil + invalidateContents() + } + + private func invalidateContents() { + if #available(iOS 13, *) { + self.layer.contents = CALayer() + } else if #available(iOS 11, *) { + super.image = nil + } else { + layer.contents = nil } } From 104240e2a69f56760f7aa3b4fbdbb053c5b676ee Mon Sep 17 00:00:00 2001 From: Dragomir Ivanov <37864243+dragomir-ivanov-212@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:28:22 +0200 Subject: [PATCH 2/5] Fixed - Background/foreground duplicates image in iOS13 --- UIImageViewAligned.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/UIImageViewAligned.swift b/UIImageViewAligned.swift index bfbb749..cefddaf 100644 --- a/UIImageViewAligned.swift +++ b/UIImageViewAligned.swift @@ -216,6 +216,8 @@ open class UIImageViewAligned: UIImageView { realImageView?.autoresizingMask = [.flexibleWidth, .flexibleHeight] realImageView?.contentMode = contentMode addSubview(realImageView!) + + NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil) } private func updateLayout() { @@ -261,4 +263,8 @@ open class UIImageViewAligned: UIImageView { private func getInspectableProperty(_ alignment: UIImageViewAlignmentMask) -> Bool { return self.alignment.contains(alignment) } + + @objc private func willEnterForeground(_ notification: Notification) { + invalidateContents() + } } From 028fc44a1a4bf2cf46d64a0033b2c8d3b1787fc9 Mon Sep 17 00:00:00 2001 From: Dragomir Ivanov <37864243+dragomir-ivanov-212@users.noreply.github.com> Date: Thu, 21 Nov 2019 17:29:55 +0200 Subject: [PATCH 3/5] Version bump --- UIImageViewAlignedSwift.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UIImageViewAlignedSwift.podspec b/UIImageViewAlignedSwift.podspec index 0818cac..e9de67b 100644 --- a/UIImageViewAlignedSwift.podspec +++ b/UIImageViewAlignedSwift.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "UIImageViewAlignedSwift" - s.version = "0.7.0" + s.version = "0.7.1" s.summary = "A UIImageView subclass which allows you to align the image left/right/top/bottom, even when contentMode is AspectFit." s.description = "It is a subclass of UIImageView that allows you to customize the alignment of the displayed image inside the view's frame. This works even if the contentMode is set to AspectFit, AspectFill or ScaleToFill." s.homepage = "https://github.com/sochalewski/UIImageViewAlignedSwift" From b513f0ea0f5135d9b1e8e07eea19245f3b4d5700 Mon Sep 17 00:00:00 2001 From: Dragomir Ivanov Date: Tue, 3 Dec 2019 11:27:09 +0200 Subject: [PATCH 4/5] Invalidate contents on tint color change --- UIImageViewAligned.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/UIImageViewAligned.swift b/UIImageViewAligned.swift index cefddaf..97cd96a 100644 --- a/UIImageViewAligned.swift +++ b/UIImageViewAligned.swift @@ -210,6 +210,11 @@ open class UIImageViewAligned: UIImageView { invalidateContents() } + open override func tintColorDidChange() { + super.tintColorDidChange() + invalidateContents() + } + private func setup(image: UIImage? = nil, highlightedImage: UIImage? = nil) { realImageView = UIImageView(image: image ?? super.image, highlightedImage: highlightedImage ?? super.highlightedImage) realImageView?.frame = bounds From 3900b66c9f2b1949961fda2ae0ba7c8c85d4a89f Mon Sep 17 00:00:00 2001 From: Dragomir Ivanov Date: Tue, 3 Dec 2019 11:41:17 +0200 Subject: [PATCH 5/5] Removed foreground notification subscription --- UIImageViewAligned.swift | 6 ------ 1 file changed, 6 deletions(-) diff --git a/UIImageViewAligned.swift b/UIImageViewAligned.swift index 97cd96a..75a561f 100644 --- a/UIImageViewAligned.swift +++ b/UIImageViewAligned.swift @@ -221,8 +221,6 @@ open class UIImageViewAligned: UIImageView { realImageView?.autoresizingMask = [.flexibleWidth, .flexibleHeight] realImageView?.contentMode = contentMode addSubview(realImageView!) - - NotificationCenter.default.addObserver(self, selector: #selector(willEnterForeground), name: UIApplication.willEnterForegroundNotification, object: nil) } private func updateLayout() { @@ -268,8 +266,4 @@ open class UIImageViewAligned: UIImageView { private func getInspectableProperty(_ alignment: UIImageViewAlignmentMask) -> Bool { return self.alignment.contains(alignment) } - - @objc private func willEnterForeground(_ notification: Notification) { - invalidateContents() - } }