Search code examples
iosswift3scale

Get view controller current scale


I've been using the .transform method of the UIViewController.view property to scaleX and scaleY my view controller.

I've been digging and couldn't find how can I check the current scale state of the VC.

I'm scaling it with:

ViewController.view.transform = CGAffineTransform.identity.scaledBy(x: 1.5, y: 1.5);

Is there any get-property like:

let currentScale = ViewController.scale ?

OR

let scaleX = ViewController.scale.x

Thanks :D


Solution

  • Try this;

    CGFloat xScale = self.view.transform.a;
    CGFloat yScale = self.view.transform.d;
    

    After applying a scale transform, a transformation will be available through the transform property (CGAffineTransform values) on UIView.

    Refer: https://developer.apple.com/reference/uikit/uiview/1622459-transform?language=objc