【问题标题】:NSWindow redraw issues/flickers when resized调整大小时 NSWindow 重绘问题/闪烁
【发布时间】:2015-01-06 07:39:03
【问题描述】:

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

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

这是一个屏幕截图,显示了调整窗口大小时的 UI 片段:

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

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

【问题讨论】:

  • 那么问题是什么?如何避免闪烁或如何解决崩溃?如果是后者,那么我们需要查看一些代码。
  • @Droppy 问题是什么可能导致闪烁。控制台输出不是崩溃,只是警告。我不知道它是否直接相关(但可能)。
  • 我会说这是相关的;除非您在视图中进行大量自定义绘图,否则您不会注意到任何闪烁。
  • 没有自定义绘图,只有屏幕截图中的窗口。我无法在另一个测试项目中重现这个,所以我怀疑这个项目的 Xcode 构建设置或另一个干扰绘图的库......

标签: macos cocoa core-graphics nswindow


【解决方案1】:

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

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

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

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

【讨论】:

  • 感谢您发布根本原因。
【解决方案2】:

我的解决方案是在很短的延迟后将该窗口放在前面,即:

- (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];
    }
}

【讨论】:

  • 所以你遇到了同样的问题?我想知道首先是什么导致了这种情况。也许是优胜美地引入的错误?...
猜你喜欢
  • 2015-04-08
  • 2023-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-11
  • 2014-12-29
相关资源
最近更新 更多