EditBox在MacOS 10.13上會使整個介面變成白色
阿新 • • 發佈:2018-12-08
沒有找到解決方案,而且我發現只addSubview到glfw上1個原生控制元件才會出現白屏,貌似當glfw中存在1個以上原生控制元件就不會出現該問題,猜測可能是glfw的BUG,我自己在UIEditBoxImpl-mac.mm的initWithFrame方法中,在建立NSTextField並addSubview到glfw上的前後,嘗試addSubview一個NSView,發現竟然好了,雖然並不清楚原理是什麼 = =,基於cocos2dx-3.5,以下附程式碼。
@implementation UIEditBoxImplMac - (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 getNSWindow] contentView] addSubview:view]; } return self; }