Search code examples
iosswiftviewscale

how to change the scale of view


I am trying to make sidebar menu like in app Euro Sport! When the menu slides from left , the sourceviewcontroller slide to left and becomes smaller.

var percentWidthOfContainer = containerView.frame.width * 0.2 // this is 20 percent of width

    var widthOfMenu = containerView.frame.width - percentWidthOfContainer

    bottomView.transform = self.offStage(widthOfMenu)

    bottomView.frame.origin.y = 60

    bottomView.frame.size = CGSizeMake(widthOfMenu, 400)

    bottomView.updateConstraints()

    menucontroller.view.frame.size = CGSizeMake(widthOfMenu, containerView.frame.height)

    menucontroller.updateViewConstraints()

Here, the bottom view is sourceviewcontroller.view. So, the question is how to scale bottom view. In my case , i can change the size but everything inside view is still in the same size.


Solution

  • You can use CGAffineTransformScale to scale instance of UIView

    For Instance

    Suppose you have an instance of UIView as

    UIView *view;
    

    // lets say you have instantiated and customized your view

    .. ..

    // Keep the original transform of the view in a variable as

    CGAffineTransform viewsOriginalTransform = view.transform;
    

    // to scale down the view use CGAffineTransformScale

    view.transform = CGAffineTransformScale(viewsOriginalTransform, 0.5, 0.5);
    

    // again to scale up the view

    view.transform = CGAffineTransformScale(viewsOriginalTransform, 1.0, 1.0);