틈틈히 적어보는 개발 일기

[iOS][Swift] View Animation 구현하기 본문

📱 iOS, Swift

[iOS][Swift] View Animation 구현하기

itllbegone 2020. 6. 8. 16:39

UIVIew.animate apple공식문서

View에 animation 추가하기

아래의 코드를 button의 action에 추가합니다.

UIView.animate(withDuration: 0.5,
                       delay: 0.1,
                       options: .curveEaseInOut,
                       animations: { () -> Void in
                        self.extendView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 350)
        },
                       completion: { (didFinish) -> Void in
        })

withDuration -> 몇 ’초’ 동안 animation을 보여 줄 것인지 정합니다.
delay -> animation을 시작하기 전 delay를 정합니다.
options -> animation의 커브값을 지정해줍니다.

이렇게 등속으로 움직이는 animation이 아닌 부드러운 느낌을 줍니다.
해당 사이트는 이곳 에서 참고가 가능하며 기본적으로 Xcode에서 지원을 합니다!
animations -> animation을 적용합니다.
completion -> 해당 animation작업이 끝난 후 필요한 작업이 있다면 작성합니다.

 

반대로 뷰가 사라지거나 줄어드는 animation을 원한다면 height값을 조절하면 됩니다.

Comments