#swift
#swift
Вопрос:
У меня есть массив UITextField, и с помощью 2 UIButtons я могу добавить или удалить один.Когда я нажимаю на кнопку, движения анимируются с помощью метода UIView.animated(), и метка под ним также работает, но когда я удаляю последнее текстовое поле, метка не анимируется.Я вставил 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()
})
Комментарии:
1. вы когда-нибудь находили решение? Я сам столкнулся с чем-то подобным.
2. @Kyle Я думаю, что проблема заключалась в ограничениях. Вы должны попробовать изменить их и выполнить layoutIfNeeded() в конце.