
每个图层都有自己的CAKeyframeAnimation对象.看看下面的代码:
我有一个接收对象的方法,创建CAKeyframeAnimation并将动画附加到它:
- (voID)animateMovingObject:(CALayer*)obj fromposition:(CGPoint)startposition toposition:(CGPoint)endposition duration:(NSTimeInterval)duration { CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; pathAnimation.calculationMode = kCAAnimationPaced; //pathAnimation.fillMode = kkCAFillModeRemoved; // default //pathAnimation.removedOnCompletion = YES; // default pathAnimation.duration = duration; // create an empty mutable path CGMutablePathref curvedpath = CGPathCreateMutable(); // set the starting point of the path CGPathMovetoPoint(curvedpath,NulL,startposition.x,startposition.y); CGPathAddCurvetoPoint(curvedpath,endposition.y,endposition.x,endposition.y); pathAnimation.path = curvedpath; [obj addAnimation:pathAnimation forKey:@"pathAnimation"]; CGPathRelease(curvedpath);} 现在,假设我在我的棋盘游戏中添加了3层作为子层,我进行了以下调用:
CALayer obj1 = ... // set up layer and add as sublayer[self animateMovingObject:obj1 fromposition:CGPointMake(0.0,0.0) toposition:CGPointMake(100.0,100.0) duration:2.0];CALayer obj2 = ... // set up layer and add as sublayer[self animateMovingObject:obj2 fromposition:CGPointMake(0.0,0.0) toposition:CGPointMake(150.0,100.0) duration:2.0];CALayer obj3 = ... // set up layer and add as sublayer[self animateMovingObject:obj3 fromposition:CGPointMake(0.0,0.0) toposition:CGPointMake(200.0,100.0) duration:2.0];
通过这样做,我只能看到obj3从位置(0.0,0.0)移动到(200.0,100.0).
我错过了什么?我应该使用NSOperationQueue / Threads吗?
使用dynamicDIDStart:CAKeyframeAnimation的delegate方法在此上下文中似乎没有用处.
有任何想法吗?
提前致谢.
@H_403_31@解决方法 如果要对这样的一系列动画进行分组,以确保它们可以同步,则可以将它们包装在CATransaction中:[CATransaction begin];[CATransaction setValue:[NSNumber numberWithfloat:2.0] forKey:kCATransactionAnimationDuration]; // Do animations[CATransaction commit];
但是,我不太清楚为什么你编写的代码不会触发每个图层的正确动画,即使它们没有同步.
请注意,通过将removedOnCompletion设置为YES,您的动画将会运行,然后对象将跳到最后的起点.你可能希望那不是.
总结以上是内存溢出为你收集整理的iphone – 同时在不同层中的多个CAKeyframeAnimation全部内容,希望文章能够帮你解决iphone – 同时在不同层中的多个CAKeyframeAnimation所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)