0
有沒有一個Swift guru知道如何將這個代碼在objective-c中轉換成Swift?Swift Guru能夠將此Objective-C塊轉換爲Swift嗎?
SCNAnimationEventBlock chainEventBlock = ^(CAAnimation *animation, id animatedObject, BOOL playingBackward) {
[self.mainSkeleton addAnimation:secondAnim forKey:secondKey];
};
if (firstAnim.animationEvents == nil || firstAnim.animationEvents.count == 0) {
firstAnim.animationEvents = @[[SCNAnimationEvent animationEventWithKeyTime:fadeTime block:chainEventBlock]];
} else {
NSMutableArray *pastEvents = [NSMutableArray arrayWithArray:firstAnim.animationEvents];
[pastEvents addObject:[SCNAnimationEvent animationEventWithKeyTime:fadeTime block:chainEventBlock]];
firstAnim.animationEvents = pastEvents;
}
在斯威夫特,我想:
var chainEventBlock : ((CAAnimation , AnyObject , Bool) -> (SCNAnimationEventBlock))?
chainEventBlock = { (animation, animatedObject, playingBackward)->(SCNAnimationEventBlock) in
return self.mainSkeleton?.addAnimation(anim2, forKey: secondKey)
}
if anim1?.animationEvents == nil || anim1?.animationEvents.count == 0 {
anim1?.animationEvents = [SCNAnimationEvent(keyTime: fadeTime, block: chainEventBlock)]
}
錯誤:
感謝
非常感謝Rengers – Paul 2015-03-18 23:27:00