【问题标题】:smooth animation in iOS using CoreAnimation使用 CoreAnimation 在 iOS 中平滑动画
【发布时间】:2010-12-13 17:11:43
【问题描述】:

CoreAnimation 是一件很容易的事情,但是:

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

我想将 ImageView 缓慢移动 100 像素。因此,所有定位值都是双倍的,我希望 Layoutsystem 以亚像素精度定位项目。 Butt 当我看这个动画时,我看到 ImageView “跳跃”像素而不是平滑的旅行。 有什么想法可以实现真正的亚像素定位吗? 我还尝试使用计时器设置位置并重新计算帧值,但效果相同。

更新: 在我的应用程序的另一部分,我使用 Accelerometer 来更新 ImageView 的位置,并基本计算图形的位置广告大小,然后执行:

MyImageView.frame = newCGRect; 

我从加速度计获得大约 60 次更新/秒,并从 Apple 的加速度计示例中添加了低通滤波器。
这里的定位是完美的?!?!
为什么 CoreAnimation 不会发生这种情况?

感谢您的帮助。

【问题讨论】:

  • 如果您尝试为 center 而不是 frame 设置动画会发生什么?
  • 可以改变插值函数吗?也许当前函数正在使用整数? (只是猜测。但这就是 CA。)
  • 我也有同样的问题。你找到解决办法了吗?

标签: iphone core-animation


【解决方案1】:

尝试使用 CGAffineTransformTranslate(MyImageView.transform, 100, 0) 代替 CGRectOffset。

参考这里: http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html

【讨论】:

    【解决方案2】:

    如果你在 QuartzCore 框架中使用 CABasicAnimation,你可以使用“CAMediaTimingFunction”来平滑你的动画。内置替代方案对我有用,但据我所知,您也可以定义自己的计时功能。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-17
      相关资源
      最近更新 更多