我的 tvOS 应用程序中有一个 UIViewController,它只会出现几秒钟,并且需要完全可自定义的 MENU 按钮处理。我像这样创建它:
- (void)viewDidLoad
{
[super viewDidLoad];
// Add a tap gesture recognizer to handle MENU presses.
UITapGestureRecognizer *tapGestureRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tapGestureRec.allowedPressTypes = @[@(UIPressTypeMenu)];
[self.view addGestureRecognizer:tapGestureRec];
}
- (void)handleTap:(UITapGestureRecognizer *)sender
{
// Code to process the MENU button is here.
}
我使用以下方式显示视图控制器pushViewController:animated:
:
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
[self pushViewController:controller animated:isAnimated];
我发现如果用户在屏幕开始出现时立即按下 MENU,而交叉淡入淡出过渡效果仍在显示,他们能够躲避 UITapGestureRecognizer 并返回到前一个屏幕,这不是故意的。他们也可能通过一遍又一遍地捣碎 MENU 来引发问题——最终他们会摆脱他们不应该做的事情。
如何确保 MENU 按下总是达到我的覆盖范围?有没有办法指定一个包含应用程序的 MENU 按钮处理程序并仍然使用 UINavigationController?