gpt4 book ai didi

ios - 同时使用不同的动画曲线对自动布局约束进行动画处理

转载 作者:行者123 更新时间:2023-11-30 11:34:12 25 4
gpt4 key购买 nike

如何同时使用不同的动画曲线对自动布局约束进行动画处理?

例如,使用线性曲线对 widthAnchorheightAnchor 进行动画处理,但对 centerXAnchorcenterYAnchor 进行动画处理(在相同的 View )和 Spring 动画。 两个动画需要同时执行。

我所知道的是如何同时为每个人设置动画(在 UIView.animate 中调用 view.layoutIfNeeded()),但是如何分别为它们设置动画?

最佳答案

您必须执行如下操作:-

UIView.animate(withDuration: 0.2, animations: {
//perform animation of height
}, completion: { _ in

UIView.animate(withDuration: 0.2, animations: {
//perform animation of width
}, completion: nil)
})

如果您想添加一些动画选项,请使用以下代码:--

 UIView.animateWithDuration(0.2, delay: 0.2, options: UIViewAnimationOptions."Set your Animationoption", animations: {
//perform animation of height
}, completion: { _ in

UIView.animateWithDuration(0.2, delay: 0.2, options: UIViewAnimationOptions."Set your Animationoption", animations: {
//perform animation of width
}, completion: nil)
})

两者一起:-

  UIView.animateWithDuration(0.2, delay: 0.2, options: UIViewAnimationOptions."Set your Animationoption", animations: {
//perform animation of width
}, completion: nil)

UIView.animateWithDuration(0.2, delay: 0.2, options: UIViewAnimationOptions."Set your Animationoption", animations: {
//perform animation of height
}, completion: nil)

谢谢。

关于ios - 同时使用不同的动画曲线对自动布局约束进行动画处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49938172/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com