Justin
Justin

Reputation: 755

Select UITextField while animating background color

How do I animate the TextField without disabling it?

UIView.animate(withDuration: 1.0, delay: 0.0, options: [.repeat, .autoreverse, .curveEaseInOut], animations: {
                    (self.phoneCell.subviews[1].subviews[1] as! UITextField).layer.backgroundColor = UIColor.black.withAlphaComponent(0.2).cgColor
                }, completion: nil)

Upvotes: 2

Views: 311

Answers (1)

vacawama
vacawama

Reputation: 154711

To allow user interaction for your UITextField during animation, you need to add the option .allowUserInteraction:

UIView.animate(withDuration: 1.0, delay: 0.0,
    options: [.repeat, .autoreverse, .curveEaseInOut, .allowUserInteraction],
    animations: {
        self.myTextField.layer.backgroundColor = UIColor.black.withAlphaComponent(0.2).cgColor
    }, completion: nil)

Upvotes: 1

Related Questions