使用CoreAnimation在iOS中平滑动画 [英] smooth animation in iOS using CoreAnimation

查看:71
本文介绍了使用CoreAnimation在iOS中平滑动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我想将ImageView缓慢移动100 Pixel像素。因此,所有定位值都是两倍。我希望Layoutsystem能够以亚像素精度定位项目。
当我观看此动画时,我看到ImageView沿像素方向跳跃,而不是平稳移动。
有什么想法可以实现真正的亚像素定位?
我还尝试使用计时器设置位置并重新计算帧值,但效果相同。

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.

更新:
在另一部分我使用App的加速度计来更新ImageView的位置,并从根本上计算图形的位置广告尺寸,然后执行以下操作:

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; 

我从Accelerometer获得约60次更新/秒,并从Accelerometer示例中添加了LowPass-Filter Apple。

这里的定位是完美的吗?!?!

为什么CoreAnimation不会发生这种情况?

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?

感谢您的帮助。

推荐答案

尝试使用CGAffineTransformTranslate(MyImageView .transform,100,0)而不是CGRectOffset。

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

此处引用:
http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference。 html

这篇关于使用CoreAnimation在iOS中平滑动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆