2016-07-05 8 views
1

現在、私はキーボードが表示または非表示になったときにキーボードでアニメーション表示をしています。ジェスチャー認識機能を追加しました。ユーザーがキーボードをタップすると消えます。KeyboardWillHowShowがまだアニメーション化されている間に呼び出されます

私が遭遇した問題は、キーボードが表示されている間にユーザーがキーボードを下ろしてキーボードを消してもキーボードが消えて、表示が下がらない場合です。私は実際に何らかの理由でビューがさらに高く動くことに気付きました。ここで

は私のキーボードのリスナーメソッドです:

func keyboardWillShow(notification: NSNotification) { 
    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() { 
     if let tabBarController = tabBarController { 
      responseNode.frame.origin.y -= keyboardSize.height-tabBarController.tabBar.frame.height 
      tableNode.view.contentInset.bottom += keyboardSize.height-tabBarController.tabBar.frame.height 
     } 
    } 
} 
func keyboardWillHide(notification: NSNotification) { 
    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() { 
     if let tabBarController = tabBarController { 
      responseNode.frame.origin.y += keyboardSize.height-tabBarController.tabBar.frame.height 
      tableNode.view.contentInset.bottom -= keyboardSize.height-tabBarController.tabBar.frame.height 
     } 
    } 
} 

、ここでは、私はキーボードを隠す方法です:

extension UIViewController { 
    func hideKeyboardWhenTappedAround() { 
     let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(UIViewController.dismissKeyboard)) 
     view.addGestureRecognizer(tap) 
    } 

    func dismissKeyboard() { 
     view.endEditing(true) 
    } 
} 

任意の助けをいただければ幸いです!

+0

を試してみてください、私はフレームを変更すると、この場合には予​​測できませんね。 – juanjo

答えて

2

可能であれば、自動レイアウトを使用してみてください。この

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { 
    self.view.endEditing(true) 
} 

func textFieldShouldReturn(textField: UITextField) -> Bool { 

    text.resignFirstResponder() 

    return true 

} 
+0

キーボードを隠す –

関連する問題