How to rotate an image by some angle which is set by programmatically?

帅比萌擦擦* 提交于 2019-12-11 09:55:07

问题


Currently I am fetching a random image from the iPad image library and showing it in UIImageView. I want to rotate it by some predefined angle which I can set.

I don't want any touch based rotation. How can I do that?


回答1:


Why not just rotate the UIImageView? Include QuartzCore framework.

#import <QuartzCore/QuartzCore.h>

self.imageView.layer.affineTransform = CGAffineTransformMakeRotation(angle)

See the documentation on CGAffineTransformMakeRotation




回答2:


you can use this one:

CGAffineTransform newTransform = CGAffineTransformMakeRotation((CGFloat)(90 * M_PI / 180.0));

self.imageView.transform = newTransform;

Here 90 in degree, You can use another angle.




回答3:


CGAffineTransform rotateTransform = CGAffineTransformMakeRotation( DEGREES_TO_RADIANS( rotateValue ) );
myObject.transform = rotateTransform;


来源:https://stackoverflow.com/questions/8064200/how-to-rotate-an-image-by-some-angle-which-is-set-by-programmatically

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