UIImageView旋转矩阵正在执行偏斜

时间:2023-02-09 09:53:41

I have a rather puzzling problem. I have a UIImageView to which I supply an angle in radians to a function that rotates it. It works fine, however I now want to offset the angle by a constant. Funny thing is if I do any sort of division or multiplication to the offset variable against M_PI the imageview is skewed and not rotated??

我有一个相当令人费解的问题。我有一个UIImageView,我以弧度为角度提供一个旋转它的函数。它工作正常,但我现在想要将角度偏移一个常数。有趣的是,如果我对M_PI的偏移量变量进行任何分割或乘法,则imageview会偏斜而不会旋转?

- (void)rotateDialToAngle: (CGFloat)angle {

    CGFloat offsetAngle = -0.075f * (2.0f * M_PI);
    offsetAngle += angle;

    if(offsetAngle >= M_PI * 2)
        offsetAngle -= M_PI * 2;
    if(offsetAngle < 0)
        offsetAngle += (M_PI * 2);

    self.clockDialImageView.transform = CGAffineTransformMakeRotation(offsetAngle);
}

The code above is the intended state. If I replace the offSetAngle calculation with M_PI it has the expected behaviour of offsetting the rotation by 180 degrees. If I replace it with M_PI / 2 or anything else, I get the skew behaviour.

上面的代码是预期的状态。如果我用M_PI替换offSetAngle计算,它具有将旋转偏移180度的预期行为。如果我用M_PI / 2或其他任何东西替换它,我会得到歪斜行为。

The if statements are used to clamp the degrees to positive degrees no greater than 360. These work as expected.

if语句用于将度数钳制到不大于360的正度。这些工作按预期工作。

Note: this is the only function in the code that does any form of transformation on the image view.

注意:这是代码中唯一一个在图像视图上进行任何形式转换的函数。

Note 2: Although the view is skewed, the rotation is still applied.

注意2:虽然视图偏斜,但仍会应用旋转。

Edit: Additional transforms in the code does not explain how the problem is SO isolated to a single line of code and an operation on a constant in that line. Edit: Looked for other transforms - Nothing. CMPopTipView is external to this controller and not used. As is DejalActivityView.

编辑:代码中的其他变换不能解释问题是如何隔离到单行代码并对该行中的常量进行操作。编辑:寻找其他变换 - 没什么。 CMPopTipView在此控制器外部,不使用。和DejalActivityView一样。

UIImageView旋转矩阵正在执行偏斜

Any other ideas?

还有其他想法吗?

1 个解决方案

#1


1  

Ok I found the issue, not sure on the "why" but the solution was to change the image view draw mode from "Scale to Fill" to "Center"

好的我发现了问题,不确定“为什么”,但解决方案是将图像视图绘制模式从“缩放到填充”更改为“中心”

I am at a total loss as to why this would affect offsetting an angle by a constant?? UIImageView旋转矩阵正在执行偏斜

我完全不知道为什么这会影响一个角度的偏移?

#1


1  

Ok I found the issue, not sure on the "why" but the solution was to change the image view draw mode from "Scale to Fill" to "Center"

好的我发现了问题,不确定“为什么”,但解决方案是将图像视图绘制模式从“缩放到填充”更改为“中心”

I am at a total loss as to why this would affect offsetting an angle by a constant?? UIImageView旋转矩阵正在执行偏斜

我完全不知道为什么这会影响一个角度的偏移?