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

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

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

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.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 12-20-2011, 12:53 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2011
Posts: 1
Sosumi is on a distinguished road
Default CGAffineTransform at an angle

Hey, I'm trying to move a UIImageView using CGAffineTransform.
I need the UIImageView to move at a specific angle (in radians).
Does anyone know how to do this?
Thanks.
Sosumi is offline   Reply With Quote
Old 12-20-2011, 08:13 PM   #2 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

Code:
UIImageView *image1;

image1.transform = CGAffineTransformMakeRotation(3.14/2);
rocotilos is offline   Reply With Quote
Old 12-20-2011, 09:00 PM   #3 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,005
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Sosumi View Post
Hey, I'm trying to move a UIImageView using CGAffineTransform.
I need the UIImageView to move at a specific angle (in radians).
Does anyone know how to do this?
Thanks.
It's not clear what you are asking.

Are you asking to shift a view controller's position as if it was moving away from it's center point on a particular compass heading?

Or are you asking how to rotate an image view in place?

Or are you asking something completely different.

If you're asking about rotating an image view in place, the other poster gave you the code you need.

If you want to know how to shift an object away from it's center point as if it was moving in a compass direction, you need to use trig to calculate the new location:


Code:
//CGFloat r = radius of movement.
//CGFloat theta = angle to move, in radians

CGFloat deltaX = r * cosf(theta);
CGFloat deltaY = r * sinf(theta);
CGPoint viewCenter = myImageView.center;
viewCenter.x += deltaX;
viewCenter.y += deltaY;
myImageView.center =  viewCenter.x;
EDIT: That code moves the object by changing it's center, which is better than changing the transform because you can change the center like that even if you're previously applied rotation or scaling to the object's transform. If you use the view's transform to shift it's position, the results will be different depending on whether or not the transformation matrix is currently the identity matrix. If the view's transform has been rotated or scaled, those changes will probably cause further changes in the view transform to do something you didn't intend. (order of operations matters a great deal with transformation matrixes.)

You could also do the calculations for deltaX and deltaY as described above, and then apply them to your view's transform using the CGAffineTransformTranslate function.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.

Last edited by Duncan C; 12-20-2011 at 09:05 PM.
Duncan C is online now   Reply With Quote
Reply

Bookmarks

Tags
angle, cgaffinetransform, core, graphics, uiview

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: 395
13 members and 382 guests
7twenty7, AppsBlogger, Creativ, Dalia, David-T, Duncan C, HemiMG, heshiming, LunarMoon, Murphy, pbart, teebee74, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

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