是否可以为UIEdgeInsets设置动画?

Cla*_*lis 4 animation uitextfield uiviewanimationtransition ios swift

我一直在尝试动画改变UIEdgeInsets.我已经尝试过使用UIView.animateWithDuration了,插件只是跳转到最终值.有谁知道这是一个不能动画的属性?或者更好的是,有人知道一种动画插图的方法吗?

举个例子:

// Starting inset values
self.searchField.placeHolderInset = UIEdgeInsets(top: 0, left: 110, bottom: 0, right: 10)

// Animation block
UIView.animateWithDuration(0.1, animations: {
        self.searchField.placeHolderInset = UIEdgeInsets(top: 0, left: 18, bottom: 0, right: 10)
})
Run Code Online (Sandbox Code Playgroud)

文本跳转到最终值,而不是在0.1秒内向左移动92个像素.searchField是一个UITextField并且.placeHolderInset是UIEdgeInset用于确定UITextField占位符文本的插入.

编辑:要达到预期的效果的另一种方式是通过改变UITextField.textAlignment.Center.Left但不会动画无论是.

rob*_*off 5

您需要调用layoutIfNeeded()动画块内部的视图.