0
我有一個自定義視圖(的NSView)與3-子視圖,佈局垂直像這樣子視圖的大小被調整大小:的NSView不能因爲設置編程
----------------------------------------------------
bar : always visible. With a button to toggle tnView Fixed height
----------------------------------------------------
tnView : height is 30 if toggled, zero if not. Height = 30 or zero
----------------------------------------------------
PDFView that takes the remaining space to to bottom Flexible height
----------------------------------------------------
該問題通過tnView可以示出(高度引起= 30)或隱藏(高度= 0)。它可以防止主視圖(這裏上述3的父視圖)被垂直尺寸調整
這是我的ViewController的代碼:
override func viewDidLoad() {
super.viewDidLoad()
tnView.autoresizingMask = NSAutoresizingMaskOptions([.viewWidthSizable, .viewHeightSizable, .viewMaxXMargin,.viewMinYMargin,.viewMaxYMargin])
tnView.translatesAutoresizingMaskIntoConstraints = true
// hide view at init
tnView.frame.origin.y += tnViewHeight // constant set to 30
tnView.frame.size.height = 0
tnView.needsDisplay = true
}
// Action connected to the toggle button
@IBAction func openTNView(_ sender: NSButton) {
// should the view be opened or closed?
let isOpenView = self.tnView.frame.size.height == 0
// Create the dictionary for animating the view
var viewDict = [String: Any]()
viewDict[NSViewAnimationTargetKey] = self.tnView
viewDict[NSViewAnimationStartFrameKey] = self.tnView.frame
var endFrame = self.tnView.frame
endFrame.origin.y -= isOpenView ? tnViewHeight : -tnViewHeight
endFrame.size.height = isOpenView ? tnViewHeight : 0
viewDict[NSViewAnimationEndFrameKey] = endFrame
// Create the view animation object
let theAnim = NSViewAnimation(viewAnimations: [viewDict])
theAnim.duration = 0.4 // in seconds
theAnim.start()
if isOpenView {
// isHidden is set to true automatically when resizing to zero => unset the flag
self.tnView.isHidden = false
}
}
的問題是,主視圖不能垂直調整大小(它的高度不能改變)。水平方向都很好。我試圖改變autoresizingMask
,但沒有成功。 有什麼想法?謝謝:-)
編輯:以下是界面生成器中的視圖結構。 The View Structure in IB http://img11.hostingpics.net/pics/550625ibstruct.png
你可以顯示代碼在哪裏創建父視圖,並將子視圖添加到父視圖的位置? – rocky
嗨洛基,我正確地編輯我的文章與圖像顯示在界面生成器的意見。其他視圖不以編程方式添加。 – vomi