[英]How to make a text to fade out and only get some letters and create a new word in swift?
你可以使用 UIView.animate
UIView.animate(withDuration: 0.5, animations: {
label.alpha = 0
})
那就是淡出動畫,你可以在動畫塊中做你想做的一切。
您可以向 UIView 添加擴展以訪問輕松淡出
extension UIView {
func fadeOut(duration: TimeInterval) {
UIView.animate(withDuration: duration, animations: {
self.alpha = 0
}
}
}
然后使用它:
label.fadeOut()
正如我所說,你可以在動畫塊中做任何你想做的事情,所以你可以改變文本,當它完成時移動它們和那些東西。 希望能幫助到你!
您必須拆分文本,然后像這樣獲取每個子字符串的第一個字符
var YourString: String = "Service Involvement Expenditure"
let sunstringArray = YourString.componentsSeparatedByString(" ")
var firstString: String = sunstringArray [0] //Service
var secondString: String = sunstringArray [1] //Involvement
var thirdString: String = sunstringArray [2] //Expenditure
現在只獲取第一個字符使用下面的代碼
var firstletter = String(firstString.characters.first!) //S
var secondletter = String(secondString.characters.first!) //I
var thirdletter = String(thirdString.characters.first!) //E
var fullFirstChar = firstletter + secondletter + thirdletter //SIE
UIView.animate(withDuration: 2.0, delay: 0.0, options: UIViewAnimationOptions.curveEaseOut, animations: {
self.fullFirstChar .alpha = 1.0
},
completion: {
(finished: Bool) -> Void in
// Fade out
UIView.animate(withDuration: 2.0, delay: 0.0, options: UIViewAnimationOptions.curveEaseIn, animations: {
self.fullFirstChar .alpha = 0.0
},
completion: {(finished: Bool) -> Void in
AppInfo.instance.isAnimationCompleted = true
})
})
我希望這個能幫上忙
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.