화면의 직사각형 영역에 대한 콘텐츠를 관리하는 개체
UIView
의 프로퍼티를 조절해서 애니메이션 효과를 줄 수 있다.
UIView 프로퍼티
class func animate(
withDuration duration: TimeInterval, // 애니메이션 시간
delay: TimeInterval, // 애니메이션 시작 딜레이
options: UIView.AnimationOptions = [], // 애니메이션 효과
animations: @escaping () -> Void, // 뷰의 프로퍼티를 변경하는 코드
completion: ((Bool) -> Void)? = nil // 애니메이션 완료 후 실행 코드
)
UIView
의 Type MethodUIView.animate(withDuration: 3, delay: 1, options: [.curveEaseInOut, .repeat]) {
self.view.backgroundColor = .systemBlue
} completion: { isFinished in
self.view.backgroundColor = .systemBackground
}
systemBlue
로 변하는 애니메이션이 3초 동안 애니메이션이 실행 후 다시 systemBackground
로 변함class func animateKeyframes(
withDuration duration: TimeInterval,
delay: TimeInterval,
options: UIView.KeyframeAnimationOptions = [],
animations: @escaping () -> Void,
completion: ((Bool) -> Void)? = nil
)
class func addKeyframe(
withRelativeStartTime frameStartTime: Double, // 해당 애니메이션이 시작하는 시간을 전체 애니메이션 시간의 비율로 표시(0~1)
relativeDuration frameDuration: Double, // 애니메이션이 진행되는 시간을 전체 애니메이션 시간의 비율로 표시(0~1)
animations: @escaping () -> Void // 애니메이션 코드
)
addKeyframe
메서드로 특정 부분만 부분적으로 애니메이션을 줄 수 있음UIView.animateKeyframes(withDuration: 3, delay: 0, options: .allowUserInteraction) {
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 1/3) {
self.view.frame = self.view.frame.offsetBy(dx: 50, dy: 50)
}
UIView.addKeyframe(withRelativeStartTime: 1/3, relativeDuration: 1) {
self.view.backgroundColor = .red
}
} completion: { isFinished in
print(isFinished)
}