Smooth animations in iOS using CoreAnimation

CoreAnimation is a pretty simple thing, but:

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

I want to slowly move ImageView to 100 Pixel veeeery. Therefore, all positioning values ​​are doubled. I expect the Layoutsystem to position elements with subpixel accuracy. Butt, when I watch this animation, I see that ImageView "jumps" into a pixel instead of the usual movement. Any ideas to come up with a real subpixel layout? I also tried to set the position with a timer and recalculate the frame values, but the same effect.

Update: In another part of my application, I use the Accelerometer to update the position of the ImageView, and basically calculate the size of the ad space on the graph, and then do:

 MyImageView.frame = newCGRect; 

I get about 60 updates / s of the Accelerometer and added the LowPass filter from Apple's Accelerometer example.
Is the positioning perfect here?!?!
Why does this not happen with CoreAnimation?

Thanks for any help.

+4
source share
2 answers

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

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

+1
source

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

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

All Articles