如果pickerVew的窗口打开,键盘会隐藏文本字段

时间:2016-06-10 19:37:47

标签: ios xcode swift keyboard textfield

我有两个textfields和一个Image pickerView按钮的tableview。 enter image description here

如果我写的东西,我的文字区域正在增加,没关系。

enter image description here

但是,如果我从我的imagePicker视图中选择照片并尝试写一些东西,我就看不到我的文本字段了。请帮忙。

enter image description here

1 个答案:

答案 0 :(得分:0)

    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)
    }
}