简体   繁体   中英

UIImageView Rotation Matrix is Performing a Skew

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??

- (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.

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

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.

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.

转换搜寻

Any other ideas?

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?? 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM