UILabel 깜빡이는 애니메이션.
func txtAnimated() {
UIView.animate(withDuration: self.txtTime,
delay: 0,
options: [.curveLinear],
animations: {
self.mDeadLineTxt.alpha = 0.0
},
completion: { _ in
UIView.animate(withDuration: self.txtTime,
delay: 0,
options: [.curveLinear],
animations: {
self.mDeadLineTxt.alpha = 1
},
completion: { _ in
if self.isTimeAnimated {
self.txtAnimated()
}
})
})
}
** 설명
self.txtTime 은 TimeInterval형이다
options 의 [.curveLinear]은 일정속도로 애니메이션 효과를 준다. ( 자세한것은 찾아보시고. )
animations를 정의해주고 self.txtTime의 시간이 지나면 completion이 호출이되는데
이 호출되는 부분에 애니메이션을 정의해준다. 완료시점에는 재귀호출로 종료해주면된다.
self.isTimeAnimated는 Bool형 이고 생명주기에따라 재귀를 멈춘다.
주의할점은 completion말고 animations 애니메이션을 중첩으로 넣어주면
일정시간에 호출이 되는것이 아니라 바로 호출되서 애니메이션이 꼬인다.
이부분 참고해서 작업하면된다.