Rotate a UIImage or UIView to a particular angle, NOT an amount of angle

我的梦境 提交于 2019-12-03 13:40:31

问题


Objective-C for iOS.

How do I rotate an image or view TO a particular angle. I have tried the two methods below, but both rotate the AMOUNT of angle, not TO the angle. Basically I would like to call a method to rotate to 90' and then say call again of 180', and the image/view to finish at 180', NOT an addition of them both (270') which is what happens if I use either of the methods below.

#define degreesToRadians(degrees) (M_PI * degrees / 180.0)

myImage.transform = CGAffineTransformMakeRotation(degreesToRadians(90));

myImage.transform = CGAffineTransformRotate(myImage.transform, degreesToRadians(90));

Many thanks!


回答1:


Reset by

.transform = CGAffineTransformIdentity

before the other transforms...




回答2:


ohho's answer can be useful if you haven't to do animation. I found useful this trick:

[UIView animateWithDuration:0.2 animations:^{
            self.compassImgView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, radians);
        }];


来源:https://stackoverflow.com/questions/3244925/rotate-a-uiimage-or-uiview-to-a-particular-angle-not-an-amount-of-angle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!