UIView Animate

  1. 우선 애니메이션은 Closure 기반으로 작성한다.

  2. Animate가 실행되는 동안에는 user Information (터치 등)이 일시적으로 disabled 되었다가, 끝나면 다시 enable

animate(withDuration:animations:) | Apple Developer Documentation

<aside> 💡 Animate changes to one or more views using the specified duration.

</aside>

class func animate(withDuration duration: TimeInterval,
             delay: TimeInterval,
           options: UIView.AnimationOptions = [],
        animations: @escaping () -> Void,
        completion: ((Bool) -> Void)? = nil)

Parameters

주의할점

  1. hidden과 같이 중간값 계산이 불가능한 속성은 적용되지 않는다.

  2. 클로저 내부에서 레이아웃에 접근해서 constant 값을 직접 바꿔주는 경우에는 애니메이션이 적용되지 않을 수 있음

    layoutIfNeeded() 를 사용하여 Update 해주자!

@objc func buttonDidTap() {
        self.animationTargetView.snp.remakeConstraints {
            $0.top.equalTo(self.view.safeAreaLayoutGuide).inset(16)
            $0.centerX.equalToSuperview()
            $0.size.equalTo(240)
        }
        
        UIView.animate(
            withDuration: 3,
            delay: 3,
            animations: {
                self.animationTargetView.layoutIfNeeded()
            }
        )
    }

[iOS - swift] Animation 테크닉 - 오토레이아웃, 단일 애니메이션, 연속 애니메이션, 스프링, 뒤집기 (autolayout, CAKeyframeAnimation, animateKeyFrames)

CGAffineTransform