没有找到解决方案,而且我发现只addSubview到glfw上1个原生控件才会出现白屏,貌似当glfw中存在1个以上原生控件就不会出现该问题,猜测可能是glfw的BUG,我自己在UIEditBoxImpl-mac.mm的initWithFrame方法中,在创建NSTextField并addSubview到glfw上的前后,尝试addSubview一个NSView,发现竟然好了,虽然并不清楚原理是什么 = =,基于cocos2dx-3.5,以下附代码。
参考 http://forum.cocos.com/t/editbox-macos-10-13/53309 代码给了下
- (instancetype)initWithFrame:(NSRect)frameRect editBox:(void *)editBox
{
self = [super init];
if (self) {
_editState = NO;
_secure = NO;
self.textField = [[[NSTextField alloc] initWithFrame:frameRect] autorelease];
self.secureTextField = [[[NSSecureTextField alloc] initWithFrame:frameRect] autorelease];
//TODO: need to delete hard code here.
NSFont *font = [NSFont systemFontOfSize:frameRect.size.height*2/3];
_textField.font = font;
_secureTextField.font = font;
[self setupTextField:_textField];
[self setupTextField:_secureTextField];
self.editBox = editBox;
self.placeholderAttributes = [NSMutableDictionary dictionaryWithObjectsAndKeys:
font, NSFontAttributeName,
[NSColor grayColor], NSForegroundColorAttributeName,
nil];
[self.window.contentView addSubview:_textField];
//解决白屏问题
NSView *view = [[NSView alloc] initWithFrame:NSZeroRect];
[self.window.contentView addSubview:view];
}
return self;
}