Is it possible to revive UIEdgeInsets?

I am trying to animate a change in UIEdgeInsets

. I've already tried using UIView.animateWithDuration

and the inserts just go to the final values. Does anyone know if this is a property that cannot be animated? Or better yet, does anyone know a way to animate an insert?

As an example:

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

      

Instead of moving 92 pixels to the left for 0.1 seconds, the text jumps to the final value. searchField

is this UITextField

, and .placeHolderInset

is the UIEdgeInset used to define the insert for the tag text UITextField

.

EDIT: Another way to achieve the desired effect is to change UITextField

.textAlignment

from .Center

to .Left

, but that will not animate either.

+4


source to share


1 answer


You need to call layoutIfNeeded()

on the view inside the animation block.



+4


source







All Articles