Animate a change with NSTextAlignment of UITextField using Swift

岁酱吖の 提交于 2019-12-12 01:56:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!