调整大小时,NSWindow重绘问题/闪烁

时间:2015-01-06 07:39:03

标签: macos cocoa core-graphics nswindow

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

我无法弄清楚为什么会这样。我将应用程序减少到最低限度:单个文档窗口控制器,其中包含一个包含大纲视图和按钮的窗口。没有后台处理,没有加载文档数据等。

以下是在调整窗口大小时显示UI片段的屏幕截图:

Sample screenshot

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

控制台中还有一个与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

2 个答案:

答案 0 :(得分:6)

作为参考,我找到了根本原因,虽然我无法解释。

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

为什么呢?老实说,我不知道。我从窗口中删除了所有控件,并在Interface Builder面板中添加了一个空表视图→出现问题。删除表格视图后,问题就消失了。

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

答案 1 :(得分:1)

我的解决方案是在一小段延迟后将窗口拉上前面,即:

- (void)awakeFromNib {
    if (WSPreferences.currentApplication.showActivityWindow) {
        // http://stackoverflow.com/questions/27794135/nswindow-redraw-issues-flickers-when-resized
        //
        [self performSelector:@selector(makeKeyAndOrderFront:) withObject:self afterDelay:0.1];
    }
}
相关问题