我一直在尝试为 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
但这也不会动画。
最佳答案
您需要在动画 block 内部的 View 上调用 layoutIfNeeded()
。
关于ios - 是否可以为 UIEdgeInsets 设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30136973/