macos - 调整大小时 NSWindow 重画问题/闪烁

标签 macos cocoa core-graphics nswindow

我最近注意到,当我调整应用程序窗口大小时,应用程序中的某些控件(NSTableView 和 NSOutlineView)会闪烁。

我不明白为什么会发生这种情况。我将应用程序缩减到最低限度:一个文档窗口 Controller ,其中包含一个包含大纲 View 和一个按钮的窗口。无后台处理、不加载文档数据等

以下屏幕截图显示了调整窗口大小期间的 UI 片段:

Sample screenshot

注意顶部轮廓 View 的片段、白色背景和偏移窗口阴影。

控制台中还有一个与 Core Graphics 相关的警告(见下文)。不确定是否与问题有关。

该应用在 Mac OS X 10.10.1 上运行,部署目标和基础 SDK 设置为 10.9。

控制台输出(不是崩溃):

<Warning>: void CGSUpdateManager::log() const: conn 0x22833 token 0x10dfffffffff3823
<Warning>: Backtrace (at 4250.73):
<Warning>: void CGSUpdateManager::log() const:  0   CoreGraphics                        0x00007fff986f5215 CGSBacktraceCreate + 59
<Warning>: void CGSUpdateManager::log() const:  1   CoreGraphics                        0x00007fff98714688 _ZN16CGSUpdateManager14disable_updateEv + 84
<Warning>: void CGSUpdateManager::log() const:  2   AppKit                              0x00007fff8e4e2de5 -[NSWindow disableScreenUpdatesUntilFlush] + 127
<Warning>: void CGSUpdateManager::log() const:  3   AppKit                              0x00007fff8e4a2250 -[NSView _gainedLayerTreeHostAncestor] + 385
<Warning>: void CGSUpdateManager::log() const:  4   AppKit                              0x00007fff8e4a20ae -[NSView _recursiveGainedLayerTreeHostAncestor] + 27
<Warning>: void CGSUpdateManager::log() const:  5   AppKit                              0x00007fff8e4a667a -[NSScroller _recursiveGainedLayerTreeHostAncestor] + 103
<Warning>: void CGSUpdateManager::log() const:  6   AppKit                              0x00007fff8e70da56 -[NSScroller _setSurfaceBacked:] + 213
<Warning>: void CGSUpdateManager::log() const:  7   AppKit                              0x00007fff8e67324f -[NSScrollView setScrollerStyle:] + 304
<Warning>: void CGSUpdateManager::log() const:  8   AppKit                              0x00007fff8ed0af27 +[NSScrollerImpPair _updateAllScrollerImpPairsForNewRecommendedScrollerStyle:] + 426
<Warning>: void CGSUpdateManager::log() const:  9   CoreFoundation                      0x00007fff8b36fcbc __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
<Warning>: void CGSUpdateManager::log() const:  10  CoreFoundation                      0x00007fff8b2611b4 _CFXNotificationPost + 3140
<Warning>: void CGSUpdateManager::log() const:  11  Foundation                          0x00007fff8b5f8ea1 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
<Warning>: void CGSUpdateManager::log() const:  12  CoreFoundation                      0x00007fff8b2d154c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
<Warning>: void CGSUpdateManager::log() const:  13  CoreFoundation                      0x00007fff8b2c3655 __CFRunLoopDoBlocks + 341
<Warning>: void CGSUpdateManager::log() const:  14  CoreFoundation                      0x00007fff8b2c2e0e __CFRunLoopRun + 910
<Warning>: void CGSUpdateManager::log() const:  15  CoreFoundation                      0x00007fff8b2c2838 CFRunLoopRunSpecific + 296
<Warning>: void CGSUpdateManager::log() const:  16  HIToolbox                           0x00007fff9980043f RunCurrentEventLoopInMode + 235
<Warning>: void CGSUpdateManager::log() const:  17  HIToolbox                           0x00007fff998000be ReceiveNextEventCommon + 179
<Warning>: void CGSUpdateManager::log() const:  18  HIToolbox                           0x00007fff997ffffb _BlockUntilNextEventMatchingListInModeWithFilter + 71
<Warning>: void CGSUpdateManager::log() const:  19  AppKit                              0x00007fff8e4266d1 _DPSNextEvent + 964
<Warning>: void CGSUpdateManager::log() const:  20  AppKit                              0x00007fff8e425e80 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 194
<Warning>: void CGSUpdateManager::log() const:  21  AppKit                              0x00007fff8e419e23 -[NSApplication run] + 594
<Warning>: void CGSUpdateManager::log() const:  22  AppKit                              0x00007fff8e4052d4 NSApplicationMain + 1832
<Warning>: void CGSUpdateManager::log() const:  23  MyApp                               0x00000001000022eb main + 75
<Warning>: void CGSUpdateManager::log() const:  24  libdyld.dylib                       0x00007fff97a025c9 start + 1

最佳答案

作为引用,我找到了根本原因,尽管我无法解释它。

applicationDidFinishLaunching: 中,我正在初始化窗口 Controller 的共享实例,并通过调用 showWindow:nil 显示其窗口。该窗口恰好包含一个 NSTableView。此表格 View 导致其他大纲 View (在不相关的窗口中)闪烁。

为什么?老实说我不知道​​。我从窗口中删除了所有控件,并直接从 Interface Builder 调色板添加了一个空 TableView → 出现问题。删除 TableView 后问题就消失了。

解决方案是不在 applicationDidFinishLaunching: 中立即打开窗口。相反,我添加了一个菜单以便稍后打开它(无论如何,它都是一个带有调试信息的窗口)。

关于macos - 调整大小时 NSWindow 重画问题/闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27794135/

相关文章:

iphone - CGDataProviderCopyData() 实际上复制字节吗?或者只是指针?

ios - 仅在圆圈内用核心图形绘制

macos - 在 Mac 上查找(并终止)锁定端口 3000 的进程

android - npx react-native run-android 不会启动模拟器,如果模拟器正在运行,也不会运行

c++ - 在 Mac 上通过命令行编译 Allegro 5 程序

objective-c - Cocoa 自定义通知示例

ios - 确定哪个 CGPath 被窃听

c - Security.h 中结构的 macOS 文档

cocoa - 在 Cocoa 中加载 OpenAL 的 .wav 文件

objective-c - 如何设置NSMenu的显示项数?