gpt4 book ai didi

cocoa - NSOpenGLView、NSWindow 和 NSResponder - makeFirstResponder 不工作

转载 作者:行者123 更新时间:2023-12-03 16:13:17 25 4
gpt4 key购买 nike

在下面的代码中,我使用 NSWindowNSOpenGLView 初始化一个 NSViewController [a NSResponder],呈现 View 并尝试将 NSViewController 设置为 Windows 第一响应者。

它不工作。我期望能够在下面的 keyUp:keyDown: 方法中命中断点,但什么也没有发生。

我错过了什么吗?

-(void)initwithFrame:(CGRect)frame 
{
window = [[MyNSWindow alloc] initWithContentRect:frame styleMask:NSClosableWindowMask | NSTitledWindowMask backing:NSBackingStoreBuffered defer: YES ];


OpenGLView* glView = [[[OpenGLView alloc] initWithFrame:window.frame] autorelease];

window.contentView = glView;

[window makeFirstResponder:self];
[window makeKeyWindow];

[window display];
}

-(void)keyDown:(NSEvent*)theEvent
{
unichar unicodeKey = [ [ theEvent characters ] characterAtIndex:0 ];
unicodeKey = 0;
}

-(void)keyUp:(NSEvent *)theEvent
{
unichar unicodeKey = [ [ theEvent characters ] characterAtIndex:0 ];
unicodeKey = 0;
}

最佳答案

回到这个问题,其实问题出在别处。

我一直在使用这个 sleep 功能来控制应用程序的帧速率:

void System::Sleep(double seconds)
{
NSDate* limit = [NSDate dateWithTimeIntervalSinceNow:seconds];
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];

[runLoop runUntilDate:limit];
}

这样做似乎会完全卡住系统并阻止关键事件。

而是使用它来安排更新功能:

[NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selector(updateApp:) userInfo:nil repeats:YES];

关于cocoa - NSOpenGLView、NSWindow 和 NSResponder - makeFirstResponder 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7475394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com