smooth animation in iOS using CoreAnimation

不羁岁月 提交于 2019-12-10 15:34:04

问题


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.


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/4431451/smooth-animation-in-ios-using-coreanimation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!