简体   繁体   English

隐藏的节点不显示为childnodewithname

[英]hidden nodes don't show up with childnodewithname

I'm building a list with a checkbox function, where the check symbol is a child of the empty check box. 我正在建立一个具有复选框功能的列表,其中复选符号是空复选框的子代。 In touchesBegan:, the checkbox should go from hidden to unhidden, and back, with each touch of the checkbox. 在touchesBegan:中,每次触摸复选框,复选框应从隐藏变为未隐藏,然后返回。 The code looks like this: 代码如下:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    if let touch = touches.first {
        location = touch.locationInNode(self)
        for node in self.nodesAtPoint(location) {
            if node.childNodeWithName("checkSymbol")?.hidden == true {
                node.childNodeWithName("checkSymbol")?.hidden = false
            } else if childNodeWithName("checkSymbol")?.hidden == false {
                node.childNodeWithName("checkSymbol")?.hidden = true
            }
        }
    }
}

The problem is the childNode (the checkSymbol node) is not being picked up by the .nodesAtPoint() method when it's hidden. 问题是当隐藏时, .nodesAtPoint()方法没有拾取childNode(checkSymbol节点)。 That's the reason I've tried to workaround using the .childNodeWithName() approach above, but the box remains checked for subsequent touches. 这就是我尝试使用上述.childNodeWithName()方法解决问题的原因,但仍选中该框以进行后续触摸。 Has anyone a suggestion for how to fix this? 有没有人建议如何解决这个问题?

If you wish for hidden nodes to be picked up by the nodesAtPoint you can always change your implementation of hidden . 如果希望由nodesAtPoint拾取隐藏节点,则可以随时更改hidden的实现。

You could alternatively use node.zPosition = -1 , presuming you have a background node with zPosition 0 to hide behind. 您也可以使用node.zPosition = -1 ,假设您有一个隐藏于zPosition 0的背景节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM