[iOS] 'setAnimationCurve' was deprecated in iOS 13.0: Use the block-based animation API instead 처리
iOS 13 이상 부터 키보드를 처리하는 부분의 Animation 의 [경고] 가 뜨고 있어서 처리하는 부분 공유드립니다.
이번에 iOS 13이상 부터는 과거에 사용되었던 개념들이 많이 사라지고 있어 경고 지우면서 변경해주는것도 하나의 일이 되어 버렸내요.
변경 전 코드
/// 키보드 위치 수정
/// - Parameter notification:
func keyboardWillAnimate(notification:Notification) {
let userInfo = notification.userInfo
let keyboardFrame = userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as! CGRect
let duration = userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as! NSNumber
let curve = userInfo?[UIResponder.keyboardAnimationCurveUserInfoKey] as! NSNumber
printDZ("ApprSignViewController KeyboardFrame\n \(keyboardFrame)")
// 키보드 높이 구해오기.
let keyboardHeight = keyboardFrame.size.height
// 키보드 애니메이션 처리
UIView.animate(withDuration: duration.doubleValue) {
// iOS 13 미만 사용했던 부분
UIView.setAnimationCurve(UIView.AnimationCurve(rawValue: curve.intValue)!)
// 내부적인 처리
// Show
if notification.name == UIResponder.keyboardWillShowNotification {
self.constraintBackViewBottom.constant = keyboardHeight
}
// Hide
else if notification.name == UIResponder.keyboardWillHideNotification {
self.constraintBackViewBottom.constant = 0
}
// #. 애니메이션 효과 참고!
self.view.layoutIfNeeded()
}
}
변경 후 코드
/// 키보드 위치 수정
/// - Parameter notification:
func keyboardWillAnimate(notification:Notification) {
let userInfo = notification.userInfo
let keyboardFrame = userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as! CGRect
let duration = userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as! NSNumber
let curve = userInfo?[UIResponder.keyboardAnimationCurveUserInfoKey] as! NSNumber
printDZ("ApprSignViewController KeyboardFrame\n \(keyboardFrame)")
// 키보드 높이 구해오기.
let keyboardHeight = keyboardFrame.size.height
// 키보드 애니메이션 처리
//animate(withDuration:delay:options:animations:completion:)
// iOS 13 이상으로 통합변경됨
UIView.animate(withDuration: duration.doubleValue, delay: 0, options: [UIView.AnimationOptions(rawValue: UInt(curve.intValue))], animations: {
// 내부적인 처리
// Show
if notification.name == UIResponder.keyboardWillShowNotification {
self.constraintBackViewBottom.constant = keyboardHeight
}
// Hide
else if notification.name == UIResponder.keyboardWillHideNotification {
self.constraintBackViewBottom.constant = 0
}
// #. 애니메이션 효과 참고!
self.view.layoutIfNeeded()
}, completion: nil)
}

댓글
댓글 쓰기