【问题标题】:iOS 13 Alternative to 'setAnimationCurve'iOS 13 替代“setAnimationCurve”
【发布时间】:2020-02-22 00:00:39
【问题描述】:

在 iOS 13 中,Apple 弃用我在我的应用中使用的许多功能。对于他们中的大多数人来说,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()

                }

            }



        }

    }

}

每当键盘出现时,我正在使用此代码在屏幕底部向上/向下滑动一个条

我将非常感谢有关此主题的任何帮助。

【问题讨论】:

    标签: ios swift uikit ios13 ios-animations


    【解决方案1】:

    如果你想要一个内置的动画曲线,调用

    animate(withDuration:delay:options:animations:completion:)
    

    options: 允许您包含动画曲线。

    但更好的选择是根本不使用 UIView 类动画调用。使用 UIViewPropertyAnimator。现在您可以应用任何您喜欢的动画曲线。

    【讨论】:

    • 感谢您的回答。您介意提供示例代码吗?我在动画方面没有经验,并且从 Stack Overflow 中得到了提到的代码
    • 当然,你的动画曲线是什么?它是内置的还是自定义的?
    • 谢谢!老实说,我不知道有什么区别?您需要更多代码吗?
    • 嗯,也许吧,但我不这么认为;我认为您正在从键盘获取动画曲线,以便与键盘一起移动某些东西,对吗?如果您这样做是为了响应keyboardWillShow 通知,则无需制作动画!你已经在一个隐式动画中;只需说出您想要的常量,它就会自动生成动画。
    • @Rivera 好问题!它不是,然后它是。 :) 我不知道变化是什么时候发生的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-17
    • 2019-10-28
    • 2020-02-14
    • 2023-02-25
    相关资源
    最近更新 更多