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 08-29-2010, 11:08 PM   #1 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default Why is the animation set back when it's finished?

Hey everyone,

haven't posted here for ages, how have you guys been?

I am working on an app at the moment and I need to rotate an image. I have found some code over at StackOverflow that does rotate my UIImageView but the problem is that once the animation is finished, the image returns to it's initial position. I don't get it. How can I make it stay where it was in the end of the animation? Because I want to be able to call the same method again afterwards and continue the rotation from where I left it last time. For example, I the image to rotate by x degrees/radians every time I call the method.

Can someone help? Here's the code I've been using (see link above)...
Code:
-(void) rotateImage {
	CABasicAnimation* rotationAnimation;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: 1.0f];
    rotationAnimation.duration = 3.0;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 1.0; 
    rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
	
    [self.theImageView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
}
Thanks in advance!

Cheers,
Bob
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Old 08-30-2010, 07:24 AM   #2 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

*Bump*

Anyone? Anything?
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Old 08-30-2010, 07:28 AM   #3 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

You need to set the final position before calling the animation.
Then make sure to set the fromValue in your animation code.
harrytheshark is offline   Reply With Quote
Old 08-31-2010, 12:33 PM   #4 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

Hi,

thanks harrytheshark! Your post made me google in the right direction, hehe.

I needed to add these lines to make it work:

Code:
rotationAnimation.fillMode = kCAFillModeForwards;
rotationAnimation.removedOnCompletion = NO;
Solution found here.

Thanks!
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Old 08-31-2010, 12:37 PM   #5 (permalink)
Registered Member
 
Join Date: Dec 2008
Location: UK
Posts: 1,896
harrytheshark is on a distinguished road
Default

Right, but you needn't add those lines if you just set the position before performing the animation.

If you don't remove the animation layer, your memory allocation will increase everytime you run the animation.

What you could do is remove the layer when the animation is finished yourself, after setting the new position, but I would definitely recommend removing it at some point.
harrytheshark is offline   Reply With Quote
Old 09-04-2010, 08:15 AM   #6 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

Thanks for the hint.

I added this line:
Code:
[self.theImageView.layer removeAllAnimations];
Then I set up the *animation and then I addAnimation: animation. Everything works perfectly now. Thanks for your help, mate.

Cheers,
Bob
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Reply

Bookmarks

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: 353
6 members and 347 guests
dre, freewind, hain, HemiMG, lendo, Newbie123
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

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