问题
I am curious if it is possible to animate a change in a UITextField's text alignment. Basically I have a UITextField that's alignment is normally set to center, and I want it to animate over to the left when the user starts editing. Here is the code that I've tried within the UITextField Delegate Methods:
func textFieldDidBeginEditing(textField: UITextField) {
UIView.animateWithDuration(0.5, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: {
self.titleField.textAlignment = NSTextAlignment.Left
self.view.layoutIfNeeded()
}, completion: nil)
}
When I tap in the text field and start editing, the text alignment does change, but it doesn't animate. I'm just wondering if what I'm trying to do would even be possible. It's in no way essential to the operation of my app, but for the situation it would look very nice.
Any and all advice is greatly appreciated. Thank You!
回答1:
Sadly, there is no way to animate a NSTextAlignment change. You can fake the effect by being smart, though. For some inspiration, see this question.
来源:https://stackoverflow.com/questions/36228378/animate-a-change-with-nstextalignment-of-uitextfield-using-swift