【发布时间】:2021-01-20 06:40:34
【问题描述】:
我在objective-c中编写了一个示例代码来绘制两个窗口并使第一个窗口成为第二个窗口的父窗口,这样当第一个窗口移动时,第二个窗口也会移动。我可以看到绘制了两个窗口,但是当我移动父窗口时子窗口没有移动。这段代码有什么问题?
NSRect frame = NSMakeRect(0, 0, 200, 200);
NSUInteger styleMask = NSTitledWindowMask;
NSRect rect = [NSWindow contentRectForFrameRect:frame styleMask:styleMask];
NSWindow * window = [[NSWindow alloc] initWithContentRect:rect styleMask:styleMask backing: NSBackingStoreBuffered defer:false];
[window setBackgroundColor:[NSColor blueColor]];
[window makeKeyAndOrderFront:NSApp];
NSRect frame1 = NSMakeRect(0, 0, 100, 100);
NSUInteger styleMask1 = NSTitledWindowMask;
NSRect rect1 = [NSWindow contentRectForFrameRect:frame1 styleMask:styleMask1];
NSWindow * window1 = [[NSWindow alloc] initWithContentRect:rect1 styleMask:styleMask1 backing: NSBackingStoreBuffered defer:false];
[window1 setBackgroundColor:[NSColor greenColor]];
[window1 makeKeyAndOrderFront:NSApp];
CFRunLoopRun();
[window1 setParentWindow:window];
【问题讨论】:
标签: objective-c macos parent-child nswindow