与iPad模拟器相比,在设备(iPad)中运行时动画更慢

时间:2012-10-17 05:32:56

标签: ipad animation core-animation bezier uibezierpath

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

这是我的代码。我正在使用bezier路径。

 [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。有没有其他方法可以加快动画的开始?

感谢。

1 个答案:

答案 0 :(得分:0)

您在基于视图的动画(UIView animateWithDuration:动画及其变体)的主体中使用CABasicAnimation和CAAnimationGroup对象。不要那样做。我很惊讶它的工作原理。这当然不是做动画的正确方法。

摆脱对UIView animateWithDuration:动画的调用:并直接使用您的CAAnimation组。