我正在尝试在键盘启动时隐藏堆栈视图,然后在键盘再次向下移动时再次取消隐藏。问题是当堆栈视图被取消隐藏时,视图(我有一些按钮)在屏幕外?
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
}
}
答案 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
}
}