我有一个UITextField数组和2个UIButtons,我可以添加或删除一个。当我单击按钮时,使用方法UIView.animated()动画动画,并且其下的标签也可以,但是当我删除了最后一个textField,标签没有动画。我用gif来弄明白我的意思。
这是代码:
let lastItem = newRecipeModel.textField[index]
newRecipeModel.textField.remove(at: index)
UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
lastItem.alpha = 0
if index>0{
self.newRecipeView.directives.topAnchor.constraint(equalTo: self.newRecipeModel.textField[index-1].bottomAnchor, constant: 15).isActive = true
self.newRecipeView.directives.leftAnchor.constraint(equalTo: self.newRecipeView.ingredientsTextField.leftAnchor).isActive = true
}else if index == 0{
self.newRecipeView.directives.topAnchor.constraint(equalTo: self.newRecipeView.ingredientsTextField.bottomAnchor, constant: 15).isActive = true
self.newRecipeView.directives.leftAnchor.constraint(equalTo: self.newRecipeView.ingredientsTextField.leftAnchor).isActive = true
}
self.view.layoutIfNeeded()
}, completion: { (true) in
lastItem.removeFromSuperview()
self.view.layoutIfNeeded()
})