Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-23-2008, 11:16 AM   #1 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 37
Default 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?

Thanks!
Norbert is offline   Reply With Quote
Old 09-23-2008, 12:28 PM   #2 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 100
Default

It would be a complex mathematical translation, Give me a few minutes, and I'll work it out for you,
spuy767 is offline   Reply With Quote
Old 09-23-2008, 02:50 PM   #3 (permalink)
New Member
 
Join Date: Jun 2008
Location: North Yorkshire, UK
Age: 27
Posts: 75
Default

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
Give that a bash, hope it helps
CaptainRedmuff is offline   Reply With Quote
Old 09-23-2008, 04:44 PM   #4 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 37
Default

Quote:
Originally Posted by CaptainRedmuff View Post
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:

Norbert is offline   Reply With Quote
Old 09-23-2008, 06:04 PM   #5 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 69
Default

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

Make sense?
skinnytron is offline   Reply With Quote
Old 09-23-2008, 06:29 PM   #6 (permalink)
New Member
 
Join Date: Aug 2008
Posts: 100
Default

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.
spuy767 is offline   Reply With Quote
Old 09-25-2008, 03:56 AM   #7 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 37
Default

Ok, thank you both for your help, I will try that.

Last edited by Norbert; 09-25-2008 at 09:36 AM.
Norbert is offline   Reply With Quote
Old 09-25-2008, 09:36 AM   #8 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 37
Default

So:

I added my image to a new UIImageView. Then with
Code:
myImageView.transform = CGAffineTransformMakeRotation(pi/4);
I was able to to the desired rotation.

But how do I get my image back into my background view so that it keeps its properties such as position, rotation, etc.? I can't figure it out.
Norbert is offline   Reply With Quote
Old 09-25-2008, 01:16 PM   #9 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 97
Default

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.
Saurman is offline   Reply With Quote
Old 09-25-2008, 04:10 PM   #10 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 37
Default

Quote:
Originally Posted by Saurman View Post
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!
Norbert is offline   Reply With Quote
Old 09-25-2008, 04:18 PM   #11 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 97
Default

Quote:
Originally Posted by Norbert View Post
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!
https://developer.apple.com/iphone/l...es/Layers.html
Saurman is offline   Reply With Quote
Old 09-26-2008, 04:44 PM   #12 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 37
Default

Hm, can someone post a quick code snippet how to add an image and then rotate/translate it?
Thanks!
Norbert is offline   Reply With Quote
Old 09-26-2008, 06:03 PM   #13 (permalink)
Registered Member
 
Join Date: Jul 2008
Posts: 97
Default

i will be doing app soon which will rotate image in the way it is in google maps, ill share my code when it will be working
Saurman is offline   Reply With Quote
Old 09-27-2008, 03:56 AM   #14 (permalink)
New Member
 
Join Date: Jul 2008
Posts: 37
Default

Quote:
Originally Posted by Saurman View Post
i will be doing app soon which will rotate image in the way it is in google maps, ill share my code when it will be working
That would be great, thanks!
Norbert is offline   Reply With Quote
Old 03-20-2009, 07:07 PM   #15 (permalink)
Registered Member
 
3DTOPO's Avatar
 
Join Date: Mar 2009
Posts: 60
Default

Quote:
Originally Posted by Saurman View Post
i will be doing app soon which will rotate image in the way it is in google maps, ill share my code when it will be working
Did you ever get it working? I would love to see your code....
3DTOPO is offline   Reply With Quote
Old 02-09-2010, 05:42 AM   #16 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 4
Cool

hi....


i have two images......how can i perform animation in them so that the first image rotates and the secomd image appears and vice versa
iphone66 is offline   Reply With Quote
Old 02-22-2010, 02:02 PM   #17 (permalink)
Obj-C Learner
 
Join Date: Apr 2009
Location: Manchester, UK
Posts: 1,030
Send a message via MSN to ZunePod Send a message via Yahoo to ZunePod
Default

I have a related question:

How about making something that looks as if it's spinning (like a vinyl on a record player)

I tried using UIView commitAnimations, but it didn't work.
__________________
Will code for food
ZunePod is offline   Reply With Quote
Old 06-30-2010, 03:43 PM   #18 (permalink)
iOS Developer
 
chaseacton's Avatar
 
Join Date: Feb 2009
Location: United States
Posts: 532
Send a message via AIM to chaseacton Send a message via Skype™ to chaseacton
Exclamation

Is there a way to do it in degrees rather than in radians?
__________________
Freelance Inquiries:
www.chaseacton.com/services

Apps:
chaseacton is offline   Reply With Quote
Old 08-17-2010, 07:30 PM   #19 (permalink)
Registered Member
 
Join Date: May 2010
Posts: 13
Default

Here is a great little macro for converting degrees to radians:

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

which you can use like :

myView.transform = CGAffineTransformMakeRotation(degreesToRadians(90) );
markkram is offline   Reply With Quote
Old 09-09-2010, 03:33 AM   #20 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 5
Default

Quote:
Originally Posted by markkram View Post
Here is a great little macro for converting degrees to radians:

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

which you can use like :

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

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.
sahil4u91 is offline   Reply With Quote
Old 09-09-2010, 03:49 AM   #21 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
Default

Quote:
Originally Posted by sahil4u91 View Post
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.
look at

imageView.layer.anchorPoint = CGPointMake(x,y);
__________________
dany_dev is offline   Reply With Quote
Old 09-13-2010, 07:50 AM   #22 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 5
Default

Quote:
Originally Posted by dany88 View Post
look at

imageView.layer.anchorPoint = CGPointMake(x,y);
Thanks dany88. It worked.
sahil4u91 is offline   Reply With Quote
Old 09-13-2010, 08:41 AM   #23 (permalink)
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,526
Default

Quote:
Originally Posted by markkram View Post
Here is a great little macro for converting degrees to radians:

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

which you can use like :

myView.transform = CGAffineTransformMakeRotation(degreesToRadians(90) );
#define degreesToRadians(x) ((x) * (M_PI / 180.0))

is twice as efficient because the compiler will figure the division at compile time.
RLScott is offline   Reply With Quote
Old 10-23-2010, 09:54 PM   #24 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 66
Default

Code:
	
angle = angle+.11;
ball.center = CGPointMake(ball.center.x + cos(angle) * 7 , ball.center.y + sin (angle) * 7);
This got a UIImageView moving in a circle for me.
mikelowe is offline   Reply With Quote
Reply

Bookmarks

Tags
image, point, rotation, uiimageview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 276
22 members and 254 guests
ADY, AragornSG, Bertrand21, Dani77, Dattee, fkmtc, HDshot, iDifferent, jakerocheleau, JasonR, jimbo, macquitzon216, mer10, prchn4christ, Rudy, sacha1996, silverwiz, sneaky, spiderguy84, Sunny46, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:07 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0