简体   繁体   中英

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. 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. That's the reason I've tried to workaround using the .childNodeWithName() approach above, but the box remains checked for subsequent touches. 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 .

You could alternatively use node.zPosition = -1 , presuming you have a background node with zPosition 0 to hide behind.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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