diff --git a/Sources/_UIKit_AnimatedImage/AnimatableCGImageView.swift b/Sources/_UIKit_AnimatedImage/AnimatableCGImageView.swift index 456e292..de159b0 100644 --- a/Sources/_UIKit_AnimatedImage/AnimatableCGImageView.swift +++ b/Sources/_UIKit_AnimatedImage/AnimatableCGImageView.swift @@ -6,17 +6,11 @@ open class AnimatableCGImageView: CGImageView { public override init(frame: CGRect) { super.init(frame: frame) - if #available(iOS 18.0, visionOS 2.0, *) { - // workaround: Designed for iPad doesn't have UIUpdateLink. - if ProcessInfo.processInfo.isiOSAppOnMac { - updateLink = BackportUpdateLink(view: self) - } else { - updateLink = UIUpdateLink(view: self) - } + if #available(iOS 18.0, visionOS 2.0, *), Self.isSupportedUIUpdateLink { + updateLink = UIUpdateLink(view: self) } else { updateLink = BackportUpdateLink(view: self) } - updateLink.isEnabled = true updateLink.preferredFrameRateRange = CAFrameRateRange( minimum: 1, maximum: 60 @@ -25,20 +19,38 @@ open class AnimatableCGImageView: CGImageView { updateContents(for: info.modelTime) }) updateLink.requiresContinuousUpdates = true + updateLink.isEnabled = true } public required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } + + static var isSupportedUIUpdateLink: Bool { + if #available(iOS 18.0, visionOS 2.0, *) { + // workaround: Designed for iPad doesn't have UIUpdateLink. + if ProcessInfo.processInfo.isiOSAppOnMac { + false + } else { + true + } + } else { + false + } + } open override func didMoveToSuperview() { super.didMoveToSuperview() - updateLink.isEnabled = true + if !Self.isSupportedUIUpdateLink { + updateLink.isEnabled = true + } } open override func removeFromSuperview() { super.removeFromSuperview() - updateLink.isEnabled = false + if !Self.isSupportedUIUpdateLink { + updateLink.isEnabled = false + } } open func updateContents(for targetTimestamp: TimeInterval) {