Siri遥控触摸位置?

时间:2015-11-10 20:07:29

标签: swift uigesturerecognizer tvos apple-tv siri-remote

当在Apple TV上收集Siri遥控器的触摸时,触摸的位置总是被报告为同一位置?

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))

}

尝试了locationInView(xxx)中的各种选项,但没有。还检查了水龙头。在调试器中,可以看到任何内容。

任何想法都是支持的。

2 个答案:

答案 0 :(得分:1)

您可以改用touchesBegan方法:

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

答案 1 :(得分:1)

您可以使用这些方法

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)")
    }
}