【问题标题】:Slower animation when run in device (iPad) compare to iPad Simulator与 iPad 模拟器相比,在设备 (iPad) 中运行时动画更慢
【发布时间】:2012-10-17 05:32:55
【问题描述】:

我的程序是产品的网格视图,单击时,图像会从原始位置动画到所需的目的地(视图控制器中的位置)。当我在 iPad 模拟器中运行它时,图像将立即开始动画,但当我在设备 (iPad) 中运行它时,它在开始动画之前给了我大约 1 秒的延迟..

这是我的代码。我正在使用贝塞尔路径。

 [UIView animateWithDuration:1.1 
                     animations:^{
                         UIBezierPath *movePath = [UIBezierPath bezierPath];
                         [movePath moveToPoint:cellImageView.center];
                         [movePath addQuadCurveToPoint:self.miniDropHereView.center
                                          controlPoint:CGPointMake(self.miniDropHereView.center.x, cellImageView.center.y)];


                         CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"];
                         moveAnim.path = movePath.CGPath;
                         moveAnim.removedOnCompletion = NO;


                         CABasicAnimation *scaleAnim = [CABasicAnimation animationWithKeyPath:@"transform"];
                         scaleAnim.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
                         scaleAnim.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)];
                         scaleAnim.removedOnCompletion = YES;

                         CABasicAnimation *opacityAnim = [CABasicAnimation animationWithKeyPath:@"alpha"];
                         opacityAnim.fromValue = [NSNumber numberWithFloat:1.0];
                         opacityAnim.toValue = [NSNumber numberWithFloat:0.1];
                         opacityAnim.removedOnCompletion = YES;

                         CAAnimationGroup *animGroup = [CAAnimationGroup animation];
                         animGroup.animations = [NSArray arrayWithObjects:moveAnim, scaleAnim, opacityAnim, nil];
                         animGroup.duration = 1;
                         [cellImageView.layer addAnimation:animGroup forKey:@"angelica"];
                         cellImageView.alpha = 0; //.0000000000000000000001;

                         self.animateProduct = animGroup;
                         self.cellImageViewGlobal = cellImageView;
                         self.animateProduct.delegate= self;
                     }
                     completion:^(BOOL finished){
                         cellImageView.alpha = 0.0000000000000000000001;
                         [cellImageView removeFromSuperview];
                     }];
}

我研究了如何在动画开始之前控制延迟。于是我改了第一行动画代码(具体如下)

 [UIView animateWithDuration:1.1 delay: 0.0f
                            options: UIViewAnimationOptionCurveEaseInOut 
                         animations:^{

但即使我没有指定延迟,动画的开始也会立即发生,在我点击产品之后(使用 iPad 模拟器时)。我不确定问题是否出在我的 iPad 上。有没有其他方法可以加快动画的开始?

谢谢。

【问题讨论】:

  • iPad 使用的 CPU 和内存系统比同时代的 Mac 慢。
  • 谢谢.. 但是还有其他方法可以加快速度吗?就像修改我的代码的某些部分一样。或者添加一些有助于加速的东西?

标签: ipad animation core-animation bezier uibezierpath


【解决方案1】:

您在基于视图的动画(UIView animateWithDuration:animations 及其变体)的主体中使用 CABasicAnimation 和 CAAnimationGroup 对象。不要那样做。我很惊讶它完全有效。这肯定不是制作动画的正确方法。

摆脱您对 UIView animateWithDuration:animations: 的调用,直接使用您的 CAAnimation 组。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-23
    • 2010-12-16
    • 1970-01-01
    • 2011-02-28
    • 2018-06-29
    • 1970-01-01
    • 2011-09-28
    • 1970-01-01
    相关资源
    最近更新 更多