NSOpenGLView,NSWindow& NSResponder - makeFirstResponder不工作 [英] NSOpenGLView, NSWindow & NSResponder - makeFirstResponder not working

查看:234
本文介绍了NSOpenGLView,NSWindow& NSResponder - makeFirstResponder不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中我正在初始化一个 NSViewController [a NSResponder], NSWindow NSOpenGLView ,显示视图并尝试将 NSViewController 设置为Windows第一响应程序。



它不工作。我希望能够在下面的 keyUp: keyDown:方法中打破一个断点,发生。



我缺少一些东西?

   - (void)initwithFrame: (CGRect)框架
{
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;
}


解决方案



我一直在使用此睡眠功能来控制应用帧速率:

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

[runLoop runUntilDate:limit];
}

这样做似乎完全冻结了系统并阻止了关键事件。 p>

而是使用此来计划更新函数:

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


In the code below I am Initialising a NSViewController [a NSResponder], with a NSWindow, a NSOpenGLView, presenting the view and attempting to set the NSViewController as the windows first responder.

It is not working. I was expecting to be able to hit a breakpoint in the keyUp: and keyDown: methods also below, but nothing is happening.

Am I missing something?

-(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;
}

解决方案

Returning to this issue, actually the problem is elsewhere.

I had been using this sleep function to control the apps frame rate:

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

    [runLoop runUntilDate:limit];
}

Doing this seems to freeze the system completely and block the key events.

Instead use this to schedule the update function:

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

这篇关于NSOpenGLView,NSWindow& NSResponder - makeFirstResponder不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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