Franziskus
Franziskus

Reputation: 41

smooth animation in iOS using CoreAnimation

CoreAnimation is a pretty easy thing, but:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:30];
MyImageView.frame = CGRectOffset(MyImageView.frame, 100, 0);
[UIView commitAnimations];

I want to move the ImageView by 100 Pixel veeeery slowly. Therefore all positioning values are double I expect the Layoutsystem to position the items with subpixel accuracy. Butt when I watch this animation i see the ImageView "jumping" pixelwise instead of a smooth traveling. Any ideas to come to a real subpixelpositioning? I also tried to set the position with a timer and recalculate the frame-values, but same effect.

Update: In an other part of my App I use the Accelerometer to update the position of a ImageView, and do basicly calculate the position ad size of the graphic an then do:

MyImageView.frame = newCGRect; 

I get around 60 Updates/s from the Accelerometer and added the LowPass-Filter from the Accelerometer example from Apple.
Here the positioning is perfect?!?!
Why does this do not happen with CoreAnimation?

Thanks for any help.

Upvotes: 4

Views: 2155

Answers (2)

Yunus Nedim Mehel
Yunus Nedim Mehel

Reputation: 12369

If you use CABasicAnimation in QuartzCore framework, you can smoothen your animation using "CAMediaTimingFunction". Built-in alternatives worked for me but as far as I know you can define your own timing functions as well.

CABasicAnimation *starShineAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
starShineAnimation.removedOnCompletion = NO;
starShineAnimation.fillMode = kCAFillModeForwards;
starShineAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
....

Upvotes: 0

Blackmuse
Blackmuse

Reputation: 11

Try using CGAffineTransformTranslate(MyImageView.transform, 100, 0) instead of CGRectOffset.

Reference here: http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html

Upvotes: 1

Related Questions