Rotating an UIImageView around an arbitrary point?
Hi,
is there a function which lets an UIImageView rotate around a given point which is not the center of the UIImageView?
If not, do you know any method how I can accomplish this?
You could simply set the center point of the UIImageView before you rotate it?
Code:
//create rect
UIImageView *myImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"my_image.png"]];
//set point of rotation
myImageView.center = CGPointMake(100.0, 100.0);
//rotate rect
myImageView.transform = CGAffineTransformMakeRotation(3.14159265); //rotation in radians
You could simply set the center point of the UIImageView before you rotate it?
Thanks, but this will let my image rotate around itself, right? I'm looking for a function or a method which lets my image rotate around a point that is not within the image. Like this:
I looked for a similar solution but couldn't find one. What I did was wrap my UIImageView in an empty UIView (ie no background or anything so that when you load the application its not visible) Then just make the UIView larger than the UIImageView and rotate the UIView.
Example: If you have a square that is 20,20 and you want to rotate at a point that was -10,-10 (ie diagonal to the top left corner). You would then make your UIView 60,60 and place the UIImageView at 40,40. If you then rotated the UIView it would appear that you were rotating it about that -10,-10 location when you would actually be rotating it about the center of the UIView (which is 30, 30).
What I was talking about earlier, you can use CGPoints to to rotate. It would be something that you would probably want to write your own class for. Expouding on what the guy said above, I would acctually recommend, if this is not something that you're going to be doing on a regular basis, make a UIView the exact width of your image, and twich the width of the orbital radius that you want the object to have. You can rotate the entire UIView, and as long as your image is a subView of the UIView, it will rotate the image.
actually, its a lot easier. U have to work with view's layer and it has so called anchorPoint and 3d rotation. Problem is - this is a part of quartz.
Oh, well, this sounds fine. What is the problem with it? Do you have any further information about layers and commands? I'm not sitting at my Mac right now so I cannot look in the XCode iPhone API.
Thanks!
Oh, well, this sounds fine. What is the problem with it? Do you have any further information about layers and commands? I'm not sitting at my Mac right now so I cannot look in the XCode iPhone API.
Thanks!
I've got an image (a straight line) and am trying to rotate it in some angle from a specific point. What happens is that the image is rotated from the center point of itself. I wan't a way through which the base of the image remains the same and it rotates in the angle I want to, just as in case of a clock.
I've got an image (a straight line) and am trying to rotate it in some angle from a specific point. What happens is that the image is rotated from the center point of itself. I wan't a way through which the base of the image remains the same and it rotates in the angle I want to, just as in case of a clock.