Daniel
Daniel

Reputation: 365

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

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

Upvotes: 1

Views: 509

Answers (1)

Reinier Melian
Reinier Melian

Reputation: 20804

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

Upvotes: 1

Related Questions