2017-09-05 66 views
0

早上好,變酥料餅HIGHT和取消隱藏的一個新領域

我有(適用於MacOS迅速4)這個豆蔻例如:

故事板

enter image description here

結果

enter image description here

在我的popover中有三個按鈕。 我在灰色按鈕上有一個IBAction。

現在我想實現下面的情況,如果我按的灰色按鈕:

enter image description here

  • 我想改變我的酥料餅的高度
  • 的文本框下方的灰色按鈕應該隱藏。
  • 兩個白色的按鈕應該動起來

改變我酥料餅的我的成功嘗試這樣的高度:

@IBAction func buttonPressed(_ sender: NSButton) { 

    self.view.window?.animator().setFrame(
    NSRect(origin: CGPoint(x: self.view.window!.frame.origin.x, y: self.view.window!.frame.origin.y), size: CGSize(width: self.view.window!.frame.width, height: self.view.window!.frame.height - 100)), display: true, animate: true) 

} 

我知道,我可以隱藏這樣的文本字段:mytextfield.isHidden = true但是我怎樣才能在同一個位置上移動兩個白色按鈕,在那裏顯示文本框?

回答

0

設置textField所在按鈕的位置。

@IBAction func buttonPressed(_ sender: NSButton) { 
    textField.isHidden = true 
    textField2.isHidden = true 
    buttonA.frame.origin.y = (textField.frame.origin.y + textField2.frame.origin.y)/2 
    buttonB.frame.origin.y = (textField.frame.origin.y + textField2.frame.origin.y)/2 
} 
+0

感謝您的解決方案。同時我找到了另一種方式來做到這一點。在我的故事板中,我設置了白色和灰色按鈕之間的垂直間距,通過IBOutlet連接此約束並將約束值設置爲10(而不是默認值100)。非常感謝 :) – Ghost108