0
我有3孩子NSWindows像主NSWindow:NSWindow與childwindows閃爍
_______________________________________
| || || |
| || || |
| || || |
| || || |
| || || |
| || || |
|_____||______________________||______|
我已經能夠向左邊和右邊子窗口的大小調整有一個按鈕的點擊,幾乎與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:您可以考慮調整大小,因爲它們已經過測試和工作。如上所述,他們在使用內容時只會閃爍。