我一直在玩一些动画,碰巧我附近没有设备可以测试。我有一个简单的云在天空中移动的动画。使用此方法对云进行动画处理:
-(void)animateLayer:(CALayer*)layer toPosition:(CGPoint)position withDuration:(CGFloat)duration{
// Prepare the animation from the current position to the new position
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.fromValue = [layer valueForKey:@"position"];
animation.toValue = [NSValue valueWithCGPoint:position];
animation.delegate = self;
animation.duration = duration;
[animation setValue:layer forKey:@"cloudLayer"];
// Update the layer's position so that the layer doesn't snap back when the animation completes.
layer.position = position;
// Add the animation, overriding the implicit animation.
[layer addAnimation:animation forKey:@"position"];
}
该层包含一个简单的部分透明图像。但是,当我运行它时,cpu 利用率比我在 MacBook Air 上预期的要高得多。有什么我做的效率低吗?还是模拟器只是在某些任务(如动画)上消耗大量资源?