iOS 13 替代“setAnimationCurve"

编程入门 行业动态 更新时间:2024-10-28 12:17:49
本文介绍了iOS 13 替代“setAnimationCurve"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

在 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-29 03:25:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1183863.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:iOS   quot   setAnimationCurve

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!