gpt4 book ai didi

ios - 删除按钮 ios swift 的所有动画

转载 作者:行者123 更新时间:2023-11-28 08:46:37 25 4
gpt4 key购买 nike

我正在创建一个带有上下动画的应用程序。当我单击一个按钮时,标题文本向上移动,标签来自底部需要在 3 秒后向下移动。看下面的示例图片

enter image description here

这是原创设计。一旦我点击一个按钮动画工作正常。但是如果我点击相同的项目动画搞砸了。我尝试使用以下代码。

self.sub_item.layer.removeAllAnimations() 
item.layer.removeAllAnimations()
self.item.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0)
self.bottomConstraint.constant = 0
self.sub_item.hidden = false

UIView.animateWithDuration(0.25, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
self.bottomConstraint.constant = self.item.frame.height/3.0
self.item.contentEdgeInsets = UIEdgeInsetsMake(-self.item.frame.height/3.0, 0, 0, 0)
self.view.layoutIfNeeded()
}, completion: { finish in
UIView.animateWithDuration(0.25, delay: 4.0, options:UIViewAnimationOptions.CurveEaseInOut, animations: {
self.bottomConstraint.constant = 0
self.nitem.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0)
self.view.layoutIfNeeded()
}, completion: {finish in
self.sub_item.hidden = true
})
})

注意:如果我的问题令人困惑,请提问。

最佳答案

只需重置约束,同时删除所有动画,就像您在点击按钮时所做的那样:-

//remove animation and reset constraints

self.sub_item.layer.removeAllAnimations()
item.layer.removeAllAnimations()
self.bottomConstraint.constant = 0
self.nitem.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0)
self.view.layoutIfNeeded()
self.view.setNeedsUpdateConstraints()
self.view.updateConstraintsIfNeeded()
self.sub_item.hidden = false

//start animation


UIView.animateWithDuration(0.25, delay: 0.0, options: UIViewAnimationOptions.BeginFromCurrentState, animations: {
self.bottomConstraint.constant = self.item.frame.height/3.0
self.item.contentEdgeInsets = UIEdgeInsetsMake(-self.item.frame.height/3.0, 0, 0, 0)
self.view.layoutIfNeeded()
}, completion: { finish in
UIView.animateWithDuration(0.25, delay: 4.0, options: UIViewAnimationOptions.BeginFromCurrentState, animations: {
self.bottomConstraint.constant = 0
self.nitem.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0)
self.view.layoutIfNeeded()
}, completion: {finish in
self.sub_item.hidden = true
})
})

关于ios - 删除按钮 ios swift 的所有动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35130390/

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