是否可以为UIEdgeInsets设置动画? [英] Is it possible to animate UIEdgeInsets?

查看:187
本文介绍了是否可以为UIEdgeInsets设置动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been trying to animate a change in UIEdgeInsets. I've already tried using UIView.animateWithDuration and the insets just jump to the final values. Does anyone know if this a property that can't be animated? Or better yet, is anyone aware of a way to animate insets?

例如:

// 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 是UIEdgeInset是用于确定 UITextField 的占位符文本的插入内容。

Instead of moving 92 pixels to the left over 0.1 seconds, the text jumps to the final value. searchField is a UITextField and .placeHolderInset is the UIEdgeInset being used to determine the insets for the UITextField's placeholder text.

编辑:达到预期效果的另一种方法是更改​​ UITextField ' s .textAlignment .Center .Left 但是那个也不会动画。

Another way to achieve the desired effect is by changing the UITextField's .textAlignment from .Center to .Left but that won't animate either.

推荐答案

你需要调用 layoutIfNeeded()在视图上,在动画块内。

You need to call layoutIfNeeded() on the view, inside of the animation block.

这篇关于是否可以为UIEdgeInsets设置动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆