首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >用不同的动画曲线同时动画AutoLayout约束

用不同的动画曲线同时动画AutoLayout约束
EN

Stack Overflow用户
提问于 2018-04-20 09:16:13
回答 2查看 395关注 0票数 0

如何同时绘制不同动画曲线的AutoLayout约束?

例如,用线性曲线动画widthAnchorheightAnchor,用spring动画动画centerXAnchorcenterYAnchor (在相同的视图上)。两种动画都需要同时进行。

我只知道如何同时给每个人动画(调用view.layoutIfNeeded() is UIView.animate),但是如何将它们分开动画呢?

EN

回答 2

Stack Overflow用户

发布于 2018-04-20 09:39:19

你必须执行如下操作:-

代码语言:javascript
运行
复制
UIView.animate(withDuration: 0.2, animations: {
    //perform animation of height
}, completion: { _ in

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

如果您想要添加一些动画选项,那么使用下面的代码:--

代码语言:javascript
运行
复制
 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)
})

两者并驾齐驱:-

代码语言:javascript
运行
复制
  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)

谢谢。

票数 0
EN

Stack Overflow用户

发布于 2018-07-04 05:19:28

您应该尝试创建CABasicAnimation,其中fromValue设置为每个视图的当前值,并在此之后调用layoutIfNeeded(),而不使用动画块。后者将改变视图的框架。如果在布局步骤之后添加动画,则修改应该是动画。

这可能是这样的

代码语言:javascript
运行
复制
let animation1 = CABasicAnimation()
let animation2 = CABasicAnimation()

animation1.fromValue = view1.center
animation1... // Set further properties to configure the animation
animation2.fromValue = ... // Same with second view
// and so on
self.view.layoutIfNeeded()
view1.layer.add(animation1, forKey: "center")
view2.layer.add(animation2, forKey: ...)

我还没试过,但我很乐意听听它是否管用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49938172

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档