diff --git a/Sources/ImageViewer_swift/ImageLoader.swift b/Sources/ImageViewer_swift/ImageLoader.swift index bef1855..d5b97db 100644 --- a/Sources/ImageViewer_swift/ImageLoader.swift +++ b/Sources/ImageViewer_swift/ImageLoader.swift @@ -22,10 +22,8 @@ public struct URLSessionImageLoader: ImageLoader { } DispatchQueue.main.async { - UIView.setAnimationsEnabled(false) imageView.image = image completion(image) - UIView.setAnimationsEnabled(true) } } } diff --git a/Sources/ImageViewer_swift/ImageViewerController.swift b/Sources/ImageViewer_swift/ImageViewerController.swift index 0221875..bad0b76 100644 --- a/Sources/ImageViewer_swift/ImageViewerController.swift +++ b/Sources/ImageViewer_swift/ImageViewerController.swift @@ -254,7 +254,6 @@ extension ImageViewerController { } func updateConstraintsForSize(_ size: CGSize) { - let yOffset = max(0, (size.height - imageView.frame.height) / 2) top.constant = yOffset bottom.constant = yOffset diff --git a/Sources/ImageViewer_swift/ImageViewerTransitionPresentationManager.swift b/Sources/ImageViewer_swift/ImageViewerTransitionPresentationManager.swift index bf0f70e..3802e66 100644 --- a/Sources/ImageViewer_swift/ImageViewerTransitionPresentationManager.swift +++ b/Sources/ImageViewer_swift/ImageViewerTransitionPresentationManager.swift @@ -21,6 +21,8 @@ final class ImageViewerTransitionPresentationAnimator:NSObject { let isPresenting: Bool let imageContentMode: UIView.ContentMode + + var observation: NSKeyValueObservation? init(isPresenting: Bool, imageContentMode: UIView.ContentMode) { self.isPresenting = isPresenting @@ -100,10 +102,14 @@ extension ImageViewerTransitionPresentationAnimator: UIViewControllerAnimatedTra UIView.animate(withDuration: duration, animations: { dummyImageView.frame = UIScreen.main.bounds controller.view.alpha = 1.0 - }) { finished in - transitionVC.targetView?.alpha = 1.0 - dummyImageView.removeFromSuperview() - completed(finished) + }) { [weak self] finished in + self?.observation = transitionVC.targetView?.observe(\.image, options: [.new, .initial]) { img, change in + if img.image != nil { + transitionVC.targetView?.alpha = 1.0 + dummyImageView.removeFromSuperview() + completed(finished) + } + } } }