Ios SceneKit场景时间偏移不工作
我正在尝试复制WWDC 2013 skinning.m幻灯片,但我在CCAnimationGroup上的时间偏移功能方面遇到了问题。当我在代码中实现时间偏移时,它不会像在Apple代码中那样偏移时间,它只是从动画的开始开始,不管我做什么 苹果所做的和我所做的有什么区别 以下是苹果公司的一段代码:Ios SceneKit场景时间偏移不工作,ios,scenekit,Ios,Scenekit,我正在尝试复制WWDC 2013 skinning.m幻灯片,但我在CCAnimationGroup上的时间偏移功能方面遇到了问题。当我在代码中实现时间偏移时,它不会像在Apple代码中那样偏移时间,它只是从动画的开始开始,不管我做什么 苹果所做的和我所做的有什么区别 以下是苹果公司的一段代码: - (void)extractAnimationsFromSceneSource:(SCNSceneSource *)sceneSource { // In this scene objects a
- (void)extractAnimationsFromSceneSource:(SCNSceneSource *)sceneSource
{
// In this scene objects are animated separately using long animations
// playing 3 successive animations. We will group these long animations
// and then split the group in 3 different animation groups.
// We could also have used three DAEs (one per animation).
NSArray *animationIDs = [sceneSource identifiersOfEntriesWithClass:[CAAnimation class]];
NSUInteger animationCount = [animationIDs count];
NSMutableArray *longAnimations = [[NSMutableArray alloc] initWithCapacity:animationCount];
CFTimeInterval maxDuration = 0;
for (NSInteger index = 0; index < animationCount; index++) {
CAAnimation *animation = [sceneSource entryWithIdentifier:animationIDs[index] withClass:[CAAnimation class]];
if (animation) {
maxDuration = MAX(maxDuration, animation.duration);
[longAnimations addObject:animation];
// NSLog(@"%@",[longAnimations description]);
}
}
CAAnimationGroup *longAnimationsGroup = [[CAAnimationGroup alloc] init];
longAnimationsGroup.animations = longAnimations;
longAnimationsGroup.duration = maxDuration;
CAAnimationGroup *idleAnimationGroup = [longAnimationsGroup copy];
idleAnimationGroup.timeOffset = 6.45833333333333;
_idleAnimationGroup = [CAAnimationGroup animation];
_idleAnimationGroup.animations = @[idleAnimationGroup];
_idleAnimationGroup.duration = 24.71 - 6.45833333333333;
_idleAnimationGroup.repeatCount = FLT_MAX;
_idleAnimationGroup.autoreverses = YES;
无论我如何更改时间偏移量,它总是从0开始。我看到苹果复制了一个带有时间偏移的动画组,然后用它来实例化一个基于该偏移的新动画组。正如您所看到的,我已经尝试在我的代码中这样做,但它并没有改变任何事情
目前我唯一能想到的是iOS不支持timeoffset属性??也许它只支持可可豆
谢谢你能提供的任何帮助 似乎在for循环中重新声明了
maxDuration
,所以最后maxDuration
仍然是0,我真是太感谢你了!!!这解决了我的问题。我已经拔头发好几天了!!
class myViewController: UIViewController,
var _idleAnimationGroup = CAAnimationGroup()
...
func extractAnimationsFromSceneSource(sceneSource: SCNSceneSource)
{
var animationsIDs = sceneSource.identifiersOfEntriesWithClass(CAAnimation.self) as [String]
var animationCount = animationsIDs.count
var longAnimations:[CAAnimation] = []
var maxDuration : CFTimeInterval = 0;
for animationID in animationsIDs {
if let animation = sceneSource.entryWithIdentifier(animationID, withClass: CAAnimation.self) as? CAAnimation {
var maxDuration = max(maxDuration, animation.duration);
longAnimations.append(animation)
}
}
var longAnimationsGroup = CAAnimationGroup()
longAnimationsGroup.animations = longAnimations
longAnimationsGroup.duration = maxDuration
var idleAnimationGroup :CAAnimationGroup = longAnimationsGroup.copy() as CAAnimationGroup
idleAnimationGroup.timeOffset = 2.5
_idleAnimationGroup.animations = [idleAnimationGroup]
_idleAnimationGroup.duration = 1.0
}