先看效果:

整個(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,效果出來就這樣