在为背景颜色设置动画时选择UITextField

时间:2017-01-15 13:44:15

标签: swift uiview uitextfield core-animation uiviewanimation

如何在不禁用TextField的情况下为TextField设置动画?

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)

1 个答案:

答案 0 :(得分:1)

要在动画期间允许用户与UITextField进行互动,您需要添加选项.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)