Home > Mobile >  How to transform view only left, right, and top using CGAffineTransform?
How to transform view only left, right, and top using CGAffineTransform?

Time:07-28

Using CGAffineTransform(scaleX: 2, y: 2) will scale up the whole view. Is there any way to transform the view only at the left, right, and top? Like the image below:

enter image description here

CodePudding user response:

You need to adjust your anchorPoint to CGPoint(x: 0.5, y: 1) with this your view will be scaled while maintain his y bottom position

customView?.layer.anchorPoint = CGPoint(x: 0.5, y: 1)
UIView.animate(withDuration: 5, animations: { [customView] in
      customView?.layer.setAffineTransform(CGAffineTransform(scaleX: 5, y: 5))
})

enter image description here

  • Related