I have follow this tutorial and everything works fine. The only issue I'm having is i can't figure out how to detect when a button has been pressed?
Thanks in advance
Author of the tutorial here, the method of adding interactivity to TVML-based apps is to use addEventListener on the DOM element in question. You can find the DOM element by holding a reference to it during creation, or by using getElementById or other such similar JavaScript DOM techniques. Also, I should mention I've added a "Part 2" to the mentioned tutorial which includes this as it's primary focus.
Here's an example of how you might do this in JS, assuming myDOMElement is a variable that references your button as a DOM element.
myDOMElement.addEventListener("select", function() { alert("CLICK!") }, false);
I have more info on the tutorial of course, so feel free to check that out, too.
Button presses are similar to UITouch events. Take a look at the UIPressEvent callbacks in the UIResponder header. UIViewControllers are part of the responder chain, so you can add the callbacks in your view controller similar to this:
- (void)pressesEnded:(NSSet<UIPress *> *)presses withEvent:(nullable UIPressesEvent *)event {
UIPress *anyPress = [presses anyObject];
// handle press event
}
let playPauseRecognizer = UITapGestureRecognizer(target: self, action: "playPauseRecognizer:")
playPauseRecognizer.allowedPressTypes = [NSNumber(integer:UIPressType.PlayPause.rawValue)]
view.addGestureRecognizer(playPauseRecognizer)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With