我嘗試編寫我自己的comboBox,因爲NSComboBox沒有我需要的功能。陰影在「主」Storyboard中繪製,但不在任何其他故事板中
因此,我創建了一個NSTextField的子類,並監視textinput並根據stringValue獲取TableView的數據。
所以當應該顯示TableView時,TextFields超級視圖將添加NSScrollView並調整它的高度等等。 所有這些工作正常。
DropShadow不太好。
因此,我在main.Storyboard中創建了一個新的Xcode-Project,添加一個NSTextField,並將該類更改爲我的子類。 只要我輸入文字,TableView就會出現,並有一個dropShadow。
接下來,我創建一個新的Storyboard,添加一個新的WindowController,並執行與main.Storyboard中相同的步驟:添加一個NSTextField,將該類更改爲我的子類。 現在我在main.Storyboard中添加一個按鈕,該按鈕有一個動作來呈現新的Storyboard。
在新的故事板中,除了TableView/ScrollView沒有任何陰影外,textfield和tableView的行爲與預期相同。
即使當我將常規選項卡中的MainInterface更改爲新的故事板時,TableView也沒有DropShadow。
兩個故事板的IB中的設置看起來是平等的。
那麼,任何提示我如何解決這個問題?
這裏是添加和顯示滾動視圖代碼:
self.scrollView = NSScrollView(frame: NSRect.zero)
self.scrollView!.documentView = self.tableView
self.scrollView!.translatesAutoresizingMaskIntoConstraints = false
self.scrollViewHeightConstraint = NSLayoutConstraint(item: self.scrollView!, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 100)
let topConstraint = NSLayoutConstraint(item: self.scrollView!, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: 0)
let widthConstraint = NSLayoutConstraint(item: self.scrollView!, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.width, multiplier: 1, constant: 0)
let leadinghConstraint = NSLayoutConstraint(item: self.scrollView!, attribute: NSLayoutAttribute.leading, relatedBy: NSLayoutRelation.equal, toItem: self, attribute: NSLayoutAttribute.leading, multiplier: 1, constant: 0)
superview.addSubview(self.scrollView!)
superview.addConstraints([self.scrollViewHeightConstraint!,topConstraint,widthConstraint,leadinghConstraint])
let dropShadow = NSShadow()
dropShadow.shadowColor = NSColor.darkGray
dropShadow.shadowOffset = NSMakeSize(0, 10.0)
dropShadow.shadowBlurRadius = 3.0
self.scrollView!.wantsLayer = true
self.scrollView!.shadow = dropShadow