From 1dea74b99b9b88d4a2292863d857768606a309c4 Mon Sep 17 00:00:00 2001 From: iWw Date: Thu, 1 Dec 2022 16:39:58 +0800 Subject: [PATCH] Add fade effect when intro change --- Sources/Marker/Marker+Draw.swift | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Sources/Marker/Marker+Draw.swift b/Sources/Marker/Marker+Draw.swift index 42f40da..926033c 100644 --- a/Sources/Marker/Marker+Draw.swift +++ b/Sources/Marker/Marker+Draw.swift @@ -27,14 +27,23 @@ extension Marker { } internal func setupIntro(calculate: Calculate) { - if let introString = current.intro as? String { - contentLabel.text = introString - } else if let attributedString = current.intro as? NSAttributedString { - contentLabel.attributedText = attributedString + // make content change has a fade effect + contentLabel.layer.removeAnimation(forKey: "marker-fade-animation") + let transition = CATransition() + transition.timingFunction = CAMediaTimingFunction(name: .easeOut) + transition.type = .fade + transition.duration = animateDuration + contentLabel.layer.add(transition, forKey: "marker-fade-animation") + + // change content + if let introString = calculate.info.intro as? String { + self.contentLabel.text = introString + } else if let attributedString = calculate.info.intro as? NSAttributedString { + self.contentLabel.attributedText = attributedString } else { - contentLabel.text = "Can not support this type: \(type(of: current.intro))" + self.contentLabel.text = "Can not support this type: \(type(of: calculate.info.intro))" } - contentLabel.frame.size = calculate.calculateContentSize(label: contentLabel) + self.contentLabel.frame.size = calculate.calculateContentSize(label: self.contentLabel) } internal func setupDimmingView(calculate: Calculate) {