Commit c88feb4a authored by pete谢兆麟's avatar pete谢兆麟

打字机demo效果

parent 562bd1e8
......@@ -300,6 +300,7 @@
047AA3F82C5CC7B0009C4554 /* YHShareStepView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047AA3F72C5CC7B0009C4554 /* YHShareStepView.swift */; };
047AA3FA2C60739E009C4554 /* YHInvitationWithGiftsSelectItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047AA3F92C60739E009C4554 /* YHInvitationWithGiftsSelectItemView.swift */; };
047AA3FC2C61EE7F009C4554 /* YHSignAppendStepView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047AA3FB2C61EE7F009C4554 /* YHSignAppendStepView.swift */; };
047AA3FF2C646844009C4554 /* YHTypingEffectViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 047AA3FE2C646844009C4554 /* YHTypingEffectViewController.swift */; };
0480976B2BA15269000B9DCA /* YHCertificateInfoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0480976A2BA15269000B9DCA /* YHCertificateInfoCell.swift */; };
0480976D2BA158A1000B9DCA /* YHCertificateListVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0480976C2BA158A1000B9DCA /* YHCertificateListVC.swift */; };
048097712BA18D66000B9DCA /* YHCertificateSearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 048097702BA18D66000B9DCA /* YHCertificateSearchBar.swift */; };
......@@ -943,6 +944,7 @@
047AA3F72C5CC7B0009C4554 /* YHShareStepView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHShareStepView.swift; sourceTree = "<group>"; };
047AA3F92C60739E009C4554 /* YHInvitationWithGiftsSelectItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHInvitationWithGiftsSelectItemView.swift; sourceTree = "<group>"; };
047AA3FB2C61EE7F009C4554 /* YHSignAppendStepView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHSignAppendStepView.swift; sourceTree = "<group>"; };
047AA3FE2C646844009C4554 /* YHTypingEffectViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHTypingEffectViewController.swift; sourceTree = "<group>"; };
0480976A2BA15269000B9DCA /* YHCertificateInfoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCertificateInfoCell.swift; sourceTree = "<group>"; };
0480976C2BA158A1000B9DCA /* YHCertificateListVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCertificateListVC.swift; sourceTree = "<group>"; };
048097702BA18D66000B9DCA /* YHCertificateSearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = YHCertificateSearchBar.swift; sourceTree = "<group>"; };
......@@ -1378,6 +1380,7 @@
children = (
0419A0992C48F87B00A5FCFA /* YHInvitationWithGiftsViewController.swift */,
047AA3D82C4A4A91009C4554 /* YHInvatationShareViewController.swift */,
047AA3FE2C646844009C4554 /* YHTypingEffectViewController.swift */,
);
path = C;
sourceTree = "<group>";
......@@ -3924,6 +3927,7 @@
044CF8D42BB6BCF700008CE8 /* YHSignatureUploadTableViewCell.swift in Sources */,
A567E5B02BD7643D00D5D5A0 /* YHHomeWebBottomView.swift in Sources */,
045EEF0D2B9F171A0022A143 /* YHBasicInfoFillCell.swift in Sources */,
047AA3FF2C646844009C4554 /* YHTypingEffectViewController.swift in Sources */,
044D0C1A2C22B40B00C5CF5E /* YHEditPersonalProfileViewController.swift in Sources */,
047AA3E82C4A6D69009C4554 /* YHListViewController.swift in Sources */,
048787D92BCF68530036E221 /* YHProgressView.swift in Sources */,
......
//
// YHTypingEffectViewController.swift
// galaxy
//
// Created by EDY on 2024/8/8.
// Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//
import UIKit
class YHTypingEffectViewController: YHBaseViewController {
private let label: UILabel = {
let label = UILabel()
label.numberOfLines = 0
label.font = UIFont.systemFont(ofSize: 18)
label.textColor = .white
label.textAlignment = .center
return label
}()
private var displayLink: CADisplayLink?
private var currentIndex: Int = 0
private var fullText: String = "恭喜您申请的【优秀人才入境计划】"
private var centerText: String = "已获得港府的正式批准!"
private var lastText: String = "从递交资料伊始,经历了235天,感谢您这一路以来对银河的信赖与包容!"
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .black
view.addSubview(label)
label.frame = view.bounds
startTypingEffect()
}
private func startTypingEffect() {
displayLink = CADisplayLink(target: self, selector: #selector(handleDisplayLink(_:)))
displayLink?.preferredFramesPerSecond = Int(1 / 0.1) // 设置帧率
displayLink?.add(to: .current, forMode: .common)
}
@objc private func handleDisplayLink(_ displayLink: CADisplayLink) {
if currentIndex < fullText.count + centerText.count + lastText.count {
var index = currentIndex
if currentIndex >= fullText.count {
index = fullText.count
}
let attributedString = NSMutableAttributedString(string: String(fullText[..<index]),
attributes: [
NSAttributedString.Key.foregroundColor: UIColor.white,
NSAttributedString.Key.paragraphStyle: {
let style = NSMutableParagraphStyle()
style.lineSpacing = 8 //控制行间距
style.alignment = .center
return style
}()
])
var centerIndex = 0
if currentIndex >= fullText.count + centerText.count {
centerIndex = centerText.count
} else if currentIndex >= fullText.count {
centerIndex = currentIndex - fullText.count
}
let centerattributedString = NSMutableAttributedString(string: String(centerText[..<centerIndex]),
attributes: [
NSAttributedString.Key.foregroundColor: UIColor.red,
NSAttributedString.Key.paragraphStyle: {
let style = NSMutableParagraphStyle()
style.lineSpacing = 8 //控制行间距
style.alignment = .center
return style
}()
])
var lastIndex = 0
if currentIndex >= fullText.count + centerText.count {
lastIndex = currentIndex - fullText.count - centerText.count
}
let lastattributedString = NSMutableAttributedString(string: String(lastText[..<lastIndex]),
attributes: [
NSAttributedString.Key.foregroundColor: UIColor.white,
NSAttributedString.Key.paragraphStyle: {
let style = NSMutableParagraphStyle()
style.lineSpacing = 8 //控制行间距
style.alignment = .center
return style
}()
])
var result = NSMutableAttributedString(attributedString: attributedString)
result.append(centerattributedString)
result.append(lastattributedString)
label.attributedText = result
currentIndex += 1
} else {
displayLink.invalidate()
}
}
}
......@@ -85,7 +85,7 @@ class YHInvitationWithGiftsViewModel: YHBaseViewModel {
if self.state < 3 {
param.updateValue(self.state + 1, forKey: "status")
}
if registered_date.isEmpty {
if !registered_date.isEmpty {
param.updateValue(registered_date, forKey: "registered_date")
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment