隐藏和取消隐藏堆栈视图

时间:2016-03-26 17:54:07

标签: ios swift

我正在尝试在键盘启动时隐藏堆栈视图,然后在键盘再次向下移动时再次取消隐藏。问题是当堆栈视图被取消隐藏时,视图(我有一些按钮)在屏幕外?

func keyboardWillShow(notification: NSNotification) {

    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
        self.view.frame.origin.y -= keyboardSize.height
        self.myStackView.hidden = true
    }
}

func keyboardWillHide(notification: NSNotification) {
    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
        self.view.frame.origin.y += keyboardSize.height
        self.myStackView.hidden = false
    }
}

1 个答案:

答案 0 :(得分:0)

您可以尝试将堆叠视图的alpha设置为0,这样它看起来似乎不可见,但仍然存在。

func keyboardWillShow(notification: NSNotification) {

    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
        self.view.frame.origin.y -= keyboardSize.height
        self.myStackView.alpha = 0
    }
}

func keyboardWillHide(notification: NSNotification) {
    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
        self.view.frame.origin.y += keyboardSize.height
        self.myStackView.alpha = 0
    }
}