iOS 13 替代“setAnimationCurve" [英] iOS 13 Alternative to 'setAnimationCurve'

查看:27
本文介绍了iOS 13 替代“setAnimationCurve"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 iOS 13 中,Apple 弃用了很多我一直在我的应用中使用的功能.对于他们中的大多数人来说,StackOverflow 上已经有很好的替代方案 - 但不是setAnimationCurve".

with iOS 13 Apple deprecated a lot of functions that I've been using in my app. For most of them, there are already alternatives well explained on StackOverflow - however not for 'setAnimationCurve'.

'setAnimationCurve' 在 iOS 13.0 中已弃用:使用基于块的动画 API 代替

'setAnimationCurve' was deprecated in iOS 13.0: Use the block-based animation API instead

这是我拥有的确切代码:

  // 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()

                }

            }



        }

    }

}

我正在使用此代码在屏幕底部向上/向下滑动一个栏,只要键盘出现.

I am using this code to slide up/down a bar on the bottom of the screen, whenever the keyboard shows up.

我将非常感谢您对此主题的任何帮助.

推荐答案

如果需要内置动画曲线,请调用

If you want a built-in animation curve, call

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

选项: 允许您包含动画曲线.

The options: lets you include an animation curve.

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

But an even better choice is not to use UIView class animation calls at all. Use a UIViewPropertyAnimator. Now you can apply any animation curve you like.

这篇关于iOS 13 替代“setAnimationCurve"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆