Scale with CGAffineTransform and set the anchor

后端 未结 2 1891
日久生厌
日久生厌 2020-12-23 12:11

If I understand correctly scaling a UIView with CGAffineTransform anchors the transformation to its center.

In particular:

         


        
相关标签:
2条回答
  • 2020-12-23 12:23

    Firstly #import <QuartzCore/QuartzCore.h> and then set the anchor points of your view:

       [[self layer] setAnchorPoint:CGPointMake(0, 0)];
    
    0 讨论(0)
  • 2020-12-23 12:35

    (a)

    Scale and then translate?

    Something like :

    CGAffineTransform t = CGAffineTransformMakeScale(2, 2);
    t = CGAffineTransformTranslate(t, width/2, height/2);
    self.transform = t;
    

    (b)

    Set the anchor point (which is probably what you want really)

    [self layer].anchorPoint = CGPointMake(0.0f, 0.0f);
    self.transform = CGAffineTransformMakeScale(2, 2);
    

    (c)

    Set the center again to make sure it's in the same place?

    CGPoint center = self.center;
    self.transform = CGAffineTransformMakeScale(2, 2);
    self.center = center;
    
    0 讨论(0)
提交回复
热议问题