如何检测Apple TV Siri Remote按钮的按下情况? [英] How to detect Apple TV Siri Remote button presses?
问题描述
根据Apple TV界面指南 ,当涉及到游戏时,如果您不在游戏的主菜单中,则应将菜单按钮用作暂停按钮(在这种情况下,应返回Apple TV OS菜单).但是,我在任何地方都找不到应该如何检测来自遥控器的硬按钮输入(与屏幕上的软按钮相对).
According to the Apple TV interface guideline, when it comes to games you're supposed to use the menu button as a pause button when you're not at the main menu of the game (in which case it should return to the Apple TV OS menu). However, I can't find anywhere how you're supposed to detect the hard button input from your remote (as opposed to soft buttons on screen).
I did find this short programming guide to using controllers that almost seems to imply that you're supposed to use the remote as a controller in this case, but I can't help but think there's a simpler way. ex.
-(void)buttonPressBegan:(NSEvent*)event
等等(那不是真的.我只是希望有类似的东西).有什么/可以通过检测的方式检测到这一点?
etc (that's not real... I'm just hoping there's something like that). What is/Is there a sanctioned way of detecting this?
推荐答案
Apple建议使用UITapGestureRecognizer
来检测按钮何时被释放.
Apple suggests using a UITapGestureRecognizer
to detect when a button is released.
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController {
UITapGestureRecognizer *tapRecognizer;
}
-(void)viewDidLoad {
[super viewDidLoad];
tapRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap:)];
tapRecognizer.allowedPressTypes = @[[NSNumber numberWithInteger:UIPressTypeMenu]];
[self.view addGestureRecognizer:tapRecognizer];
}
-(void)handleTap:(UITapGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(@"Menu button released");
}
}
For a complete list of UIPressType
's refer to UIPress Class Reference.
这篇关于如何检测Apple TV Siri Remote按钮的按下情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!