如果 pickerVew 的 window 打开,键盘会隐藏文本框
The keyboard hides textfield, if pickerVew's window opened
我有一个带有两个文本字段和一个图像选择器视图按钮的表格视图。
如果我写东西,我的文本框会变大,没关系。
但是,如果我从我的 imagePicker 视图中选择照片并尝试写一些东西,我看不到我的文本字段。请帮忙。
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardDidShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardDidHideNotification, object: nil)
}
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
func keyboardWillShow(notification: NSNotification) {
if let userInfo = notification.userInfo {
if let keyboardHeight = userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue.size.height {
tableView.contentInset = UIEdgeInsetsMake(0, 0, keyboardHeight, 0)
}
}
}
func keyboardWillHide(notification: NSNotification) {
if let userInfo = notification.userInfo {
tableView.contentInset = UIEdgeInsetsMake(50, 0, 0, 0)
}
}
我有一个带有两个文本字段和一个图像选择器视图按钮的表格视图。
如果我写东西,我的文本框会变大,没关系。
但是,如果我从我的 imagePicker 视图中选择照片并尝试写一些东西,我看不到我的文本字段。请帮忙。
override func viewDidLoad() {
super.viewDidLoad()
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardDidShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardDidHideNotification, object: nil)
}
deinit {
NSNotificationCenter.defaultCenter().removeObserver(self)
}
func keyboardWillShow(notification: NSNotification) {
if let userInfo = notification.userInfo {
if let keyboardHeight = userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue.size.height {
tableView.contentInset = UIEdgeInsetsMake(0, 0, keyboardHeight, 0)
}
}
}
func keyboardWillHide(notification: NSNotification) {
if let userInfo = notification.userInfo {
tableView.contentInset = UIEdgeInsetsMake(50, 0, 0, 0)
}
}