2017-01-15 41 views
2

如何爲TextField設置動畫而不禁用它?在動畫背景顏色的同時選擇UITextField

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

爲了讓動畫過程中的用戶交互爲您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)