NSWindow与childwindows闪烁

时间:2014-12-02 17:08:37

标签: ios swift xcode6

我有一个主要的NSWindow,有3个孩子NSWindows,如:

_______________________________________
|     ||                      ||      |
|     ||                      ||      |
|     ||                      ||      |
|     ||                      ||      |
|     ||                      ||      |
|     ||                      ||      |
|_____||______________________||______|

我已经能够通过单击按钮来调整左右子窗口的大小,与Xcode侧栏的效果几乎相同,但是当我向子窗口添加内容时(因为,例如,一个NSTableView)如果我关闭其中一个侧边栏,我会在关闭后执行的任何调整大小上获得闪烁和延迟效果。甚至正常调整主窗口的大小。任何想法为什么会发生这种情况?

代码1:侧边栏的删除操作。

var newFrame: NSRect
if sender.selectedSegment == 0 {      //leftToolbar button clicked
    if leftToolbar.frame.width > 0 {       //leftToolbar is closed
        newFrame = self.leftToolbar.frame
        newFrame.size.width = 0
        self.leftToolbar.setFrame(newFrame, display: true, animate: true)
    } else {
        newFrame = self.leftToolbar.frame
        newFrame.size.width = self.sidebarsWidth
        self.leftToolbar.setFrame(newFrame, display: true, animate: true)
    }
}

代码2:调整大小的NSNotification。

func windowResized(notification: NSNotification) {
    var win = notification.object as NSWindow
    // (...)    code from main window resizing
    if (win.isEqual(self.leftToolbar)) {    // Resizing or Animation of the left sidebar
        leftTable!.view.frame = (self.leftToolbar.contentView as NSView).frame
        var newFrame = self.mainContent.frame
        if self.leftToolbar.frame.width > 0 {     // if the sidebar is open
            newFrame.origin.x = self.mainWin.frame.origin.x+self.leftToolbar.frame.width+10.0
            newFrame.origin.y = self.mainWin.frame.origin.y+5.0
            if self.rightToolbar.frame.width > 0 {      // if right sidebar is open
                newFrame.size.width = self.mainWin.frame.width-10.0-10.0-self.leftToolbar.frame.width-self.rightToolbar.frame.width
            } else {
                newFrame.size.width = self.mainWin.frame.width-10.0-5.0-self.leftToolbar.frame.width-self.rightToolbar.frame.width
            }
        } else {      // sidebar is now closed
            newFrame.origin.x = self.mainWin.frame.origin.x+self.leftToolbar.frame.width+5.0
            newFrame.origin.y = self.mainWin.frame.origin.y+5.0
            if self.rightToolbar.frame.width > 0 {      // if right sidebar is open
                newFrame.size.width = self.mainWin.frame.width-5.0-10.0-self.leftToolbar.frame.width-self.rightToolbar.frame.width
            } else {
                newFrame.size.width = self.mainWin.frame.width-5.0-5.0-self.leftToolbar.frame.width-self.rightToolbar.frame.width
            }
        }
        self.mainContent.setFrame(newFrame, display: true)      // set the mid (child) window to occupy the space inherited from the left sidebar
    }
    // (...)   Code from right sidebar resizing
}

注意1:这是我的代码,由我开发而不是从某处复制。

注意2:您可以认为调整大小正常,因为它们已经过测试和运行。如上所述,它们只有闪烁内容。

1 个答案:

答案 0 :(得分:0)

得解决问题。子窗口设置为0宽度的帧,获取内存转储或类似的东西,因此,将子窗口设置为1宽度并“隐藏”它们是正确的解决方案。