2

When gathering touches on the Siri Remote on Apple TV the location of the touch is alway reported back as the same location ?

let tapRecognizer = UITapGestureRecognizer(target: self, action: "tapped:")
    tapRecognizer.allowedPressTypes = [NSNumber(integer: UIPressType.LeftArrow.rawValue),NSNumber(integer: UIPressType.RightArrow.rawValue)];
    self.view.addGestureRecognizer(tapRecognizer)


func tapped(tap :UITapGestureRecognizer){
print(__FUNCTION__)
    print(tap.locationInView(super.view))

}

Tried various option in locationInView(xxx) but nothing. Also examined tap. in the debugger and can see anything.

Any ideas, is it supported.

J0hnnieMac
  • 21
  • 1
  • 1
    found this here http://www.marisibrothers.com/2015/10/interacting-with-new-apple-tv-remote.html so looks like I can't – J0hnnieMac Nov 10 '15 at 20:36

3 Answers3

1

You can use the touchesBegan method instead:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for var touch in touches {
      print(touch.locationInView(self.view))
    }
}

note - the syntax shown here is historic and does not now work

Fattie
  • 27,874
  • 70
  • 431
  • 719
Stefan
  • 5,203
  • 8
  • 27
  • 51
  • unfortunately it always reports the same touchLocation :( Does all seem a bit weird since it is all based around screen input and not trackpad input. Perhaps in a future release. – J0hnnieMac Nov 11 '15 at 07:09
  • Fort anyone googling here, this does work perfectly these days (2022) – Fattie Oct 24 '22 at 17:34
0

You can use these methods

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch in touches {
        let location = touch.locationInNode(self)
        print("touchesBegan: x: \(location.x)   y: \(location.y)")
    }
}

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch in touches {
        let location = touch.locationInNode(self)
        print("touchesMoved: x: \(location.x)   y: \(location.y)")
    }
}

override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
    for touch in touches {
        let location = touch.locationInNode(self)
        print("touchesEnded: x: \(location.x)   y: \(location.y)")
    }
}
Thyselius
  • 864
  • 1
  • 10
  • 14
0

This works perfectly.

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    guard touches.count == 1, let t = touches.first else { return }
    print(t.location(in: view))
}

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
    guard touches.count == 1, let t = touches.first else { return }
    print(t.location(in: view))
}

It's a bit strange, but if you simply use "the view of the view controller" it works fine.

Don't forget that the apple remote DOES "RESET" when you put your finger "down". Each time you put your finger down, that's the new "center".

Fattie
  • 27,874
  • 70
  • 431
  • 719