先看效果:
整个效果我是用label和view拼接起来的,笨方法
视图前部我用的是个label来显示文字,重点说后面的动画,上代码:
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,效果出来就这样