UIview上下跳動(dòng)黑點(diǎn)的小動(dòng)畫

先看效果:


我是圖

整個(gè)效果我是用label和view拼接起來的,笨方法

視圖前部我用的是個(gè)label來顯示文字,重點(diǎn)說后面的動(dòng)畫,上代碼:

for i in0..<3 {

? ? ? ? ? ? let animationView =UIView.init()

? ? ? ? ? ? animationView.backgroundColor=UIColor.black

? ? ? ? ? ? animationView.frame=CGRect(x:4+ i *8, y:16, width:4, height:4)

? ? ? ? ? ? animationView.layer.cornerRadius=2

? ? ? ? ? ? animationView.layer.masksToBounds=true

? ? ? ? ? ? waitView?.addSubview(animationView)


? ? ? ? ? ? let animation =CABasicAnimation(keyPath:"transform.translation.y")

? ? ? ? ? ? animation.fromValue=NSNumber(value:-6)

? ? ? ? ? ? animation.toValue=NSNumber(value:6)

? ? ? ? ? ? animation.duration=0.5

? ? ? ? ? ? animation.repeatCount=HUGE

? ? ? ? ? ? animation.autoreverses=true

? ? ? ? ? ? animation.isRemovedOnCompletion=true

? ? ? ? ? ? DispatchQueue.main.asyncAfter(deadline: .now() +0.2*Double(i) +0.1) {

? ? ? ? ? ? ? ? animationView.layer.add(animation, forKey:"addLayerAnimationTranformTranslationY")

? ? ? ? ? ? }

? ? ? ? }

OK,效果出來就這樣

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容