Rotate UIView around its center keeping its size

前端 未结 10 1121
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 14:17

I\'m trying to rotate an UIView a few radians but after applying the transformation it doesn\'t look to be keeping its size. What\'s the proper way to achieve t

10条回答
  •  遥遥无期
    2020-12-02 14:34

    The CGAffineTransformRotate transformation rotates from an existing affine transform. The fact that you are using CGAffineTransformIdentity might be the issue. You must specify the current transform of your view.

    #define DEGREES_TO_RADIANS(angle) ((angle) / 180.0 * M_PI)
    ...
    double rads = DEGREES_TO_RADIANS(240);
    CGAffineTransform transform = CGAffineTransformRotate(self.arrowView.transform, rads);
    self.arrowView.transform = transform;
    

    Also, you might want to consider:

    self.arrowView.transform = CGAffineTransformMakeRotation(rads);
    

    EDIT : If you can, share what you kind of transformation (animated/inanimate , single/iterative) you want to achieve. I believe there might be a better, optimized way of doing this.

提交回复
热议问题