任何人是否知道为什么这在Xcode 7 GM中不再有效?
我已经调试并验证过,但即使节点出现在场景中,它们也不再将触摸事件传递给父节点。
以下是一个完整的例子。如果您从“新的Sprite Kit游戏”中替换默认的GameScene,您可以自己重现它。
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
let card = Card(imageNamed: "card_background_blank")
card.name = "Card"
let stack = Stack(imageNamed: "stack_background")
stack.name = "Stack"
addChild(stack)
stack.addChild(card)
card.position = CGPointMake(100,100)
stack.zPosition = 1
card.zPosition = 1
stack.position = CGPointMake(506,428)
card.userInteractionEnabled = false
stack.userInteractionEnabled = true
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
print("Touch")
moveAllCardsAndReturn()
}
func moveAllCardsAndReturn () {
var wait:NSTimeInterval = 1.0
let waitIncrement:NSTimeInterval = 0.05
let duration:NSTimeInterval = 0.15
func removeAndMove(card:Card) {
let oldParent = card.parent!
card.removeFromParent()
addChild(card)
card.position = CGPointMake(500,48)
var sequence = [SKAction]()
sequence.append(SKAction.waitForDuration(wait))
sequence.append(SKAction.runBlock({
card.removeFromParent()
oldParent.addChild(card)
card.position = CGPointMake(100,100)
}))
card.runAction(SKAction.sequence(sequence))
wait += waitIncrement
}
let stack = childNodeWithName("Stack")
let card = stack?.childNodeWithName("Card")
removeAndMove(card as! Card)
}
}
class Stack:SKSpriteNode {
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
print("Stack Touch")
}
}
class Card:SKSpriteNode {
}
如果场景正常工作,但触摸不再传递给父节点,即使userInteractionEnabled对于卡为false,对于卡的父节点为true(堆栈:SKSpriteNode)
所以,我用一个有效的测试用例更新了这个。这是一个错误,因为它适用于iOS 8.4 sim,但不适用于9 GM。我已将它提交给苹果。