iOS 13中,苹果公司已经放弃了我在应用程序中使用的许多功能。 对于其中的大部分功能,已经在StackOverflow上有很好的替代方法解释 - 但对于“setAnimationCurve”没有。
“setAnimationCurve”在iOS 13.0中已被弃用:改用基于块的动画API
这是我具体的代码:
// MARK: - Keyboard up/down adjustment for the addMediaBar
@objc func keyboardWillShow(notification: NSNotification) {
if let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue {
let userInfo = notification.userInfo! as [AnyHashable: Any]
let animationDuration = userInfo[UIResponder.keyboardAnimationDurationUserInfoKey] as! NSNumber
let animationCurve = userInfo[UIResponder.keyboardAnimationCurveUserInfoKey] as! NSNumber
if addMediaBarBottomAnchor.constant == 0 {
let window = UIApplication.shared.windows.filter {$0.isKeyWindow}.first
if let bottomPadding = window?.safeAreaInsets.bottom {
print(keyboardSize.height)
print(bottomPadding)
UIView.setAnimationCurve(UIView.AnimationCurve(rawValue: animationCurve.intValue)!)
UIView.animate(withDuration: animationDuration.doubleValue) {
self.addMediaBarBottomAnchor.constant = -keyboardSize.height + bottomPadding
self.view.layoutIfNeeded()
}
} else {
UIView.setAnimationCurve(UIView.AnimationCurve(rawValue: animationCurve.intValue)!)
UIView.animate(withDuration: animationDuration.doubleValue) {
self.addMediaBarBottomAnchor.constant = -keyboardSize.height
self.view.layoutIfNeeded()
}
}
}
}
}
每当键盘出现时,我使用这段代码来上下滑动屏幕底部的一栏。
对于这个主题的任何帮助,我将非常感激。
keyboardWillShow
通知时执行此操作,则无需进行动画处理!您已经处于隐式动画状态;只需说明您希望常量是什么,它就会自动进行动画处理。 - mattlayoutIfNeeded
)。只需设置约束constant
,你就完成了。 - matt