是否有可能animationUIEdgeInsets?

我一直试图在UIEdgeInsets改变animation。 我已经尝试使用UIView.animateWithDuration和insets只是跳转到最后的值。 有没有人知道这是一个不能animation的属性? 或者更好的是,是否有人知道一个animation内嵌的方法?

举个例子:

 // 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) }) 

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

编辑:另一种达到预期效果的方法是将UITextField.textAlignment.Center .textAlignment.Center ,但不会animation。

您需要在animation块内的视图上调用layoutIfNeeded()