I am having an odd problem with my UIView animations and a UITextfield - I need to be able to click a button, have the button animate up to reveal a textfield so the user can enter text in the text field, then when the user presses that button again user interaction is disabled on the text field and the button moves back over.
I have accomplished this to an extent by placing the textfield behind the button and disabling it at the start, then when the button is clicked the button animates up to reveal the text field, which becomes enabled:
Problem is that the button click is being triggered (or possibly just the animation) when the user goes to edit the text field. So when they go to type, the button just moves back down and covers the text field.
This is odd because I have a boolean to set whether the button moves up or down, and I do not think this is being flipped because often the button moves BELOW the textfield, which should never happen.
Here is how I'm doing this:
@IBAction func enterText(sender: UIButton) {
print("time to enter text")
if !textOpen
{
UIView.animateWithDuration(0.5, animations: {
self.textBtn.center.y -= self.textBtn.bounds.height
})
happenedTxt.userInteractionEnabled = true
}
else {
UIView.animateWithDuration(0.5, animations: {
self.textBtn.center.y += self.textBtn.bounds.height
})
happenedTxt.userInteractionEnabled = false
}
textOpen = !textOpen
}
How can I trigger the button move ONLY when the button is pressed? Why is the textfield triggering the animation? Is there some call being made to return the button to its original position?