1

I have a custom UIView that can be simplified down to:

class Node: UIView {
    override init(frame: CGRect) {
        super.init(frame: frame)

        let tapGR = UITapGestureRecognizer(target: self, action: "createChildNode")
        addGestureRecognizer(tapGR)
        userInteractionsEnabled = true
    }

    /* ... */

    func createChildNode() {
        let childNode = Node(frame: self.bounds.offset(dx: 100, dy: 100))
        self.addSubview(childNode)
    }
}

The first (root) node is created in the view controller:

override func viewDidLoad() {
    super.viewDidLoad()
    self.view.addSubview(Node(x: 100, y: 100, width: 150, height: 40))
}

For the root node, everything works as expected. However, for the children of the root node, nothing works.

To make sure that I wasn't using the UITapGestureRecognizer incorrectly, I tried to override the raw touchesBegan function for the Node class and do a simple println("tapped"). However the problem persisted and seems to be that the subviews do not receive any touches at all.

What could be causing this?

Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
Shimmen
  • 39
  • 6
  • May be a long shot but try setting the minimum and maximum # of touches. – Oxcug Oct 26 '14 at 21:18
  • @theMonster Tried that now but with no success. The thing is that not even the raw input handling function touchesBegan is firing, so I'm pretty sure there is nothing wrong with the UITapGestureRecognizer. – Shimmen Oct 26 '14 at 21:35

1 Answers1

0

Sounds like you just need to pass the touch events through the view hierarchy. This answer should help:

https://stackoverflow.com/a/21436355/3259329

Community
  • 1
  • 1
Oxcug
  • 6,524
  • 2
  • 31
  • 46
  • This doesn't solve my problem. First of all, it doesn't seem to work at all for me, but I also don't want to send the message back to the root. Every child should be able to spawn their own child nodes without interacting with any other node. Or am I misunderstanding something? – Shimmen Oct 26 '14 at 21:56