iOS, Swift/Tip, Bug, Swift Error
Swift ) iOS animate spring 효과넣기 - EEYatHo iOS
EEYatHo
2021. 2. 19. 20:59
반응형
여태껏 단순히 한방향으로 움직이고,
움직이는 속도를 조절하는 애니메이션만 알고있었다.
그런데 목표지점에 도착한 뒤, 살짝 튕기고 제자리로 돌아오는
일명 스프링 효과가 있었단걸 알았다.
usingSpringWithDamping
0.0 ~ 1.0
0.0에 가까울수록 심하게 튕기고, 1.0이면 튕기지 않는다
initialSpringVelocity
0.0 ~ 1.0
0.0에 가까울수록 튕길 때 속도가 빠르다
예시 )
UIView.animate(withDuration: 0.1, delay: 0, animations: {
// 일단 밑에 레이아웃하기 위한 버퍼 애니메이션
container.alpha = 1
},
completion: { _ in
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: .curveEaseInOut, animations: {
// 위로 올리기
container.snp.updateConstraints {
$0.bottom.equalToSuperview().offset(-20)
}
container.superview?.layoutIfNeeded()
},
completion: { _ in
UIView.animate(withDuration: 0.5, delay: 1, usingSpringWithDamping: 0.5, initialSpringVelocity: 0.5, options: .curveEaseInOut, animations: {
// 밑으로 내리기
container.snp.updateConstraints {
$0.bottom.equalToSuperview().offset(100)
}
container.superview?.layoutIfNeeded()
},
completion: { _ in
container.removeFromSuperview()
})
})
})
}