我一直在尝试动画改变
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)
})
与其在0.1秒内向左移动92个像素,文本会直接跳到最终值。 searchField
是一个 UITextField
,.placeHolderInset
是用于确定 UITextField
占位符文本插图的 UIEdgeInset。
编辑:另一种实现所需效果的方法是将 UITextField
的 .textAlignment
从 .Center
更改为 .Left
,但这也不会产生动画效果。
self.searchField.layoutIfNeeded()
。这样有帮助吗? - rob mayoff