SceneKit场景时间偏移无效

时间:2015-01-04 04:08:53

标签: ios scenekit

我正在尝试复制WWDC 2013 skinning.m幻灯片,但我遇到了CCAnimationGroup上的timeOffset函数问题。当我在我的代码中实现timeoffset时,它不会像在apple代码中那样抵消时间,它只是从我动画的开头开始,无论我做什么。

苹果做了什么做了什么区别?

这里有一段苹果代码:

- (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;

}

这是我在swift中的代码:

在类中初始化动画:

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


}

无论我如何设置时间偏移,它总是从0开始。我看到苹果已经复制了一个带有时间偏移的动画组,然后用它来实例化一个基于该偏移量的新动画组。我已经尝试在我的代码中执行此操作,但是它没有改变任何内容!!

我现在能想到的是iOS不支持timeoffset属性吗?也许它只有可可支持?

感谢您提供的任何帮助!

0 个答案:

没有答案