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 06-20-2011, 09:48 PM   #1 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 30
robotkid249 is on a distinguished road
Default Simple Animation Problem

Hello fellow developers,

I am trying to make an application where, when you launch the app and image starts to rotate automatically after launch. For some reason the way I am doing it, it needs a button or something to rotate, but I want it to rotate automatically. Maybe I have to take it out of the IBAction.. Or I don't know. I am pretty new to programming. Any help would be AWESOME!

It's simple code. The .h sets up the image and - (IBAction)rotate; The .m then does:
Code:
- (IBAction)rotate {
    
    // starts the animation
    [UIView beginAnimations:nil context:NULL];
    // sets the time before animation occurs
    [UIView setAnimationDelay:0];
    // sets the length of the animation
    [UIView setAnimationDuration:2.0];
    [UIView setAnimationRepeatCount:3]; //spin it 3 times. 
    // 3.14 is pi. -3.14 would be counter clockwise
    CGAffineTransform transform = CGAffineTransformMakeRotation(3.14/2);
    //square is the UIImageView getting rotated
    square.transform = CGAffineTransformRotate(transform, 3.14/2);
    // ends animation
    [UIView commitAnimations];
}
robotkid249 is offline   Reply With Quote
Old 06-20-2011, 09:52 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Make it void and call the method in viewDidLoad.
Domele is offline   Reply With Quote
Old 06-21-2011, 08:18 AM   #3 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 30
robotkid249 is on a distinguished road
Default

Thanks I fixed it, but I have more questions.

Last edited by robotkid249; 06-21-2011 at 09:18 AM.
robotkid249 is offline   Reply With Quote
Old 06-21-2011, 09:17 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 30
robotkid249 is on a distinguished road
Default

Now here is the problem. I did exactly what you said and put the animation code inside of the - (void)viewDidLoad and the spin animation starts automatically like I wanted it to. However, every time the image gets back to 0˚, it slows down and then speeds back up... Is there anyway I can get it to smoothly rotate? Thanks!
robotkid249 is offline   Reply With Quote
Old 06-21-2011, 04:02 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by robotkid249 View Post
Now here is the problem. I did exactly what you said and put the animation code inside of the - (void)viewDidLoad and the spin animation starts automatically like I wanted it to. However, every time the image gets back to 0˚, it slows down and then speeds back up... Is there anyway I can get it to smoothly rotate? Thanks!
Animations use ease-in-ease-out timing by default. Add the following line between your beginAnimations and commitAnimations:


Code:
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
Do a search in the XCode docs for "setAnimationCurve". The documentation explains it pretty well.
__________________
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.
Duncan C is offline   Reply With Quote
Old 06-21-2011, 04:14 PM   #6 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

It technically doesn't matter but I meant make the method you had void instead of IBAction (also void but if you aren't using it in Interface Builder take it out) and call the method in viewDidLoad.
Domele is offline   Reply With Quote
Old 06-21-2011, 06:16 PM   #7 (permalink)
Registered Member
 
Join Date: Jun 2011
Posts: 30
robotkid249 is on a distinguished road
Default

@ Duncan C

Thanks so much. I did exactly what you said and it worked but... When the image rotates, it goes 360˚ but when it gets to around 357˚ it skips. It is not a fully smooth transition. Any suggestions?

Code:
- (void)viewDidLoad
{
    
    [super viewDidLoad];
    
    // starts the animation
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationCurve: UIViewAnimationCurveLinear];
    // sets the time before animation occurs
    // sets the length of the animation
    [UIView setAnimationDuration:4.0];
    [UIView setAnimationRepeatCount:1e100f]; //spin it forever.
    // 3.14 is pi. -3.14 would be counter clockwise
    CGAffineTransform transform = CGAffineTransformMakeRotation(3.14/2);
    //bluegoal is the UIImageView getting rotated
    bluegoal.transform = CGAffineTransformRotate(transform, 3.14/2);
    // ends animation
    [UIView commitAnimations];
    

    
    // Do any additional setup after loading the view from its nib.
}
robotkid249 is offline   Reply With Quote
Old 08-01-2011, 03:36 PM   #8 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 5
jbernhardt is on a distinguished road
Default similar problem

The following code works but "transform" jumps into position while "transform2" rotates to position. I want them to both rotate to position.

The code is in a method called by didLoad.

Any help would be greatly appreciated.
Thanks.

Code:
    distRad = distDeg * 3.14157 / 180;
    [UIView beginAnimations:nil context:NULL];
    
    
    [UIView setAnimationDuration:4.0];
    [UIView setAnimationRepeatCount:100000]; //spin it forever.
    [UIView setAnimationCurve: UIViewAnimationCurveLinear];
    CGAffineTransform transform = CGAffineTransformMakeRotation(distRad);
   
    
    fTailMove.transform = transform;
    [UIView setAnimationCurve: UIViewAnimationCurveLinear];
    CGAffineTransform transform2 = CGAffineTransformMakeRotation(-distRad);
    fTailMove.transform = transform2;
    [UIView commitAnimations];
jbernhardt is offline   Reply With Quote
Old 08-01-2011, 09:26 PM   #9 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by jbernhardt View Post
The following code works but "transform" jumps into position while "transform2" rotates to position. I want them to both rotate to position.

The code is in a method called by didLoad.

Any help would be greatly appreciated.
Thanks.

Code:
    distRad = distDeg * 3.14157 / 180;
    [UIView beginAnimations:nil context:NULL];
    
    
    [UIView setAnimationDuration:4.0];
    [UIView setAnimationRepeatCount:100000]; //spin it forever.
    [UIView setAnimationCurve: UIViewAnimationCurveLinear];
    CGAffineTransform transform = CGAffineTransformMakeRotation(distRad);
   
    
    fTailMove.transform = transform;
    [UIView setAnimationCurve: UIViewAnimationCurveLinear];
    CGAffineTransform transform2 = CGAffineTransformMakeRotation(-distRad);
    fTailMove.transform = transform2;
    [UIView commitAnimations];
You also asked this same question in a new thread.

DON'T DO THAT! It's maddening, and will get you blackballed if you do it repeatedly.
__________________
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.
Duncan C is offline   Reply With Quote
Old 08-02-2011, 09:42 AM   #10 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 5
jbernhardt is on a distinguished road
Default @Duncan

Quote:
Originally Posted by Duncan C View Post
You also asked this same question in a new thread.

DON'T DO THAT! It's maddening, and will get you blackballed if you do it repeatedly.
I apologize for the double post. After posting on this thread, I thought this thread might be closed and then created a new one.

Thanks for your help.
jbernhardt is offline   Reply With Quote
Reply

Bookmarks

Tags
animation, problem, rotate, uiimage

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: 326
8 members and 318 guests
chemistry, Dnnake, iOS.Lover, lendo, leostc, Leslie80, pbart, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,664
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Leslie80
Powered by vBadvanced CMPS v3.1.0

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