退出全屏模式后如何接收NSView的键盘事件? [英] How to receive keyboard events for a NSView after exiting fullscreen mode?

查看:181
本文介绍了退出全屏模式后如何接收NSView的键盘事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将NSView子类化,并在应用程序启动完成后启动全屏模式.该视图在应用程序委托中作为属性fooView可用.

I subclass an NSView and start full screen mode when the application finished launching. The view is available as the property fooView in the application delegate.

// AppDelegate.m
- (void)applicationDidFinishLaunching:(NSNotification*)notification {
  [[self window] makeKeyAndOrderFront:self];
  [[self fooView] enterFullScreenMode:[NSScreen mainScreen] withOptions:nil];
}

FooView本身实现以下功能.

// FooView.m
- (void)keyDown:(NSEvent*)event {
  NSLog(@"%@ %@ - %@", self.className, NSStringFromSelector(_cmd), event);
  [self interpretKeyEvents:[NSArray arrayWithObject:event]];
}
- (void)cancelOperation:(id)sender {
  NSLog(@"%@ %@ - %@", self.className, NSStringFromSelector(_cmd), sender);
  [self exitFullScreenModeWithOptions:nil];
}

离开全屏模式后,视图不再接收键盘事件.为什么?

After leaving the fullscreen mode, the view no longer receives keyboard events. Why?

修改:
似乎与我退出全屏模式有关.当我单击视图(不是窗口)时,keyDown:cancelOperation:会在以下内容中做出响应.


It seems to have something to do with how I exit the fullscreen mode. When I click into the view (not the window) the keyDown: and cancelOperation: do respond in the following.

推荐答案

问题是包含视图的窗口确实收到了任何键盘事件.离开全屏模式后,需要将窗口设为第一响应者.

The problem was that the window containing the view did receive any keyboard events. One needs to make the window the first responder after leaving the full screen mode.

- (void)cancelOperation:(id)sender {
  NSLog(@"%@ %@ - %@", self.className, NSStringFromSelector(_cmd), sender);
  [self exitFullScreenModeWithOptions:nil];
  [self.window makeFirstResponder:self];
}

这篇关于退出全屏模式后如何接收NSView的键盘事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆