From f20d311336f13e629f51c137c3a01ad5ae22b7fe Mon Sep 17 00:00:00 2001 From: karthus <675377091@qq.com> Date: Fri, 9 Dec 2022 14:39:45 +0800 Subject: [PATCH] fix motif rerender animated --- Example/Example/ViewController.swift | 8 +++--- Sources/did-motif-ios/DIDMotifView.swift | 32 +++++++++++++++++------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index e3e098f..8ca44d3 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -131,16 +131,16 @@ class ViewController: UIViewController { } private func renderWithSpecificShape() { - motifView1.renderWith(address: "zNKb2kbCvDHo9APDhD1trbAV1EVoYF6PcSJ3", shape: .square) + motifView1.renderWith(address: "zNKb2kbCvDHo9APDhD1trbAV1EVoYF6PcSJ3", shape: .square, animated: false) didLabel1.text = "zNKb2kbCvDHo9APDhD1trbAV1EVoYF6PcSJ3" - motifView2.renderWith(address: "zNKb2kbCvDHo9APDhD1trbAV1EVoYF6PcSJ3", shape: .circle) + motifView2.renderWith(address: "zNKb2kbCvDHo9APDhD1trbAV1EVoYF6PcSJ3", shape: .circle, animated: false) didLabel2.text = "zNKb2kbCvDHo9APDhD1trbAV1EVoYF6PcSJ3" - motifView3.renderWith(address: "zNKb2kbCvDHo9APDhD1trbAV1EVoYF6PcSJ3", shape: .rectangle) + motifView3.renderWith(address: "zNKb2kbCvDHo9APDhD1trbAV1EVoYF6PcSJ3", shape: .rectangle, animated: false) didLabel3.text = "zNKb2kbCvDHo9APDhD1trbAV1EVoYF6PcSJ3" - motifView4.renderWith(address: "zNKb2kbCvDHo9APDhD1trbAV1EVoYF6PcSJ3", shape: .hexagon) + motifView4.renderWith(address: "zNKb2kbCvDHo9APDhD1trbAV1EVoYF6PcSJ3", shape: .hexagon, animated: false) didLabel4.text = "zNKb2kbCvDHo9APDhD1trbAV1EVoYF6PcSJ3" } diff --git a/Sources/did-motif-ios/DIDMotifView.swift b/Sources/did-motif-ios/DIDMotifView.swift index 7c8136a..3df89eb 100644 --- a/Sources/did-motif-ios/DIDMotifView.swift +++ b/Sources/did-motif-ios/DIDMotifView.swift @@ -58,14 +58,7 @@ public class DIDMotifView: UIView { // MARK: - UI Functions extension DIDMotifView { private func commonInit() { - layer.addSublayer(shapeLayer) - for _ in 0...7 { - let subLayer = CAShapeLayer() - subLayer.isHidden = true - subLayer.fillColor = UIColor(white: 1, alpha: 0.5).cgColor - shapeLayer.addSublayer(subLayer) - hexagonLayers.append(subLayer) - } + addSubLayers() } private func setupUI() { @@ -132,6 +125,25 @@ extension DIDMotifView { anim.initialVelocity = 4 return anim } + + private func addSubLayers() { + layer.addSublayer(shapeLayer) + for _ in 0...7 { + let subLayer = CAShapeLayer() + subLayer.isHidden = true + subLayer.fillColor = UIColor(white: 1, alpha: 0.5).cgColor + shapeLayer.addSublayer(subLayer) + hexagonLayers.append(subLayer) + } + } + + private func clearSubLayers() { + shapeLayer.removeFromSuperlayer() + hexagonLayers.forEach { subLayer in + subLayer.removeFromSuperlayer() + } + hexagonLayers.removeAll() + } } // MARK: - Action Functions extension DIDMotifView { @@ -153,7 +165,9 @@ extension DIDMotifView { self.address = address self.shape = shape self.animated = animated - + + clearSubLayers() + addSubLayers() decodeAddress() } }