Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change width UIView by animation and center

I have a view and need change width from 100 to 200 by animation.

UIView.animate(withDuration: 5
            ,animations: {
                    self.backgroundPlaceHolderView.frame.size.width += 200
})

when running this code, my view change width, but I need a change in width from the center, but this code increase view to the right enter image description here

like image 638
Rasoul Miri Avatar asked Dec 14 '18 13:12

Rasoul Miri


1 Answers

If you really need to do it with frames, here's a code snippet:

UIView.animate(withDuration: 1, animations: {
        self.backgroudPlaceHolderView.frame.origin.x -= 100
        self.backgroudPlaceHolderView.frame.size.width += 200
    })
like image 128
gulyashki Avatar answered Sep 27 '22 20:09

gulyashki