开发者

smooth animation in iOS using CoreAnimation

开发者 https://www.devze.com 2023-01-30 03:09 出处:网络
CoreAnimation is a pretty easy thing, but: [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:30];

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开发者_StackOverflow 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.


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


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];
....
0

精彩评论

暂无评论...
验证码 换一张
取 消