2016-07-09 3 views
1

私はコメントとユーザーを持っているアプリケーションに取り組んでいます。ユーザーがテーブルビューにコメントを挿入する必要があります。私が直面している問題は、フィールドにはキーボードが表示され、テキストフィールドは下のコードのように表示されます。キーボードの上にTextFiledキーボードの問題

しかし、キーボードの言語を変更したり、キーボードを絵文字に変更したり、テキストフィールドに適用される自動修正を開いたりすると、キーボードレイアウトで移動しないという問題があります。

override func viewWillAppear(animated: Bool) { 

    super.viewWillAppear(animated) 

    // KeyBoard Show and Hide 

    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(Commants_Page.keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object:nil) 
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(Commants_Page.keyboardWillHide(_:)), name: UIKeyboardWillHideNotification, object: nil) 


    NSNotificationCenter.defaultCenter().addObserver(self,selector: #selector(Commants_Page.adjustForKeyboard(_:)),name: UIKeyboardWillChangeFrameNotification,object: nil) 

} 


// KeyBoard Show and Hide Function 

func keyboardWillShow(notification: NSNotification) { 

    if KeyBoardMove == false { 

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

      KeyBoardMove = true 
     } 
    } 
} 

func keyboardWillHide(notification: NSNotification) { 

    if KeyBoardMove == true { 

     if let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue() { 
      self.view.frame.origin.y += keyboardSize.height 

      KeyBoardMove = false 
     } 
    } 
} 

Screenshot

答えて

0

私は同じ問題に直面し、以下のように仕事を周りにいたら。私はこれが完璧な解決策であるかどうかはわかりませんが、私にとっては期待通りに働いています。だからあなたはそれを試すことができます。私が何をしたか

です:

  1. viewWillAppear
  2. UITextInputCurrentInputModeDidChangeNotification通知を追加キーボードタイプに
  3. ハンドルを決定するためにchangeInputModeメソッドを実装keyboardWillShowkeyboardWillHide

    var isEmoji = Bool() 
    
    override func viewWillAppear(animated: Bool) { 
    
    super.viewWillAppear(animated) 
    
    isEmoji = false 
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "changeInputMode:", name:UITextInputCurrentInputModeDidChangeNotification, object: nil) 
    
    } 
    
    func changeInputMode(notification : NSNotification) 
    { 
        //Emoji keyboard does not have any primary language whereas normal text keyboard does have. Therefore, on the bases of it we can determine the keyboard type 
    
        if let lang = txtComment.textInputMode?.primaryLanguage 
        { 
         isEmoji = false 
        } 
        else{ 
         isEmoji = true 
        } 
    } 
    
    func keyboardWillShow(notification: NSNotification) { 
        if let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue() { 
         print(isEmoji) 
         if(!isEmoji){     
    
          writeCommentView.frame.origin.y -= keyboardSize.height 
         } 
         else{ 
          writeCommentView.frame.origin.y -= 37 //where 37 is the height differece between normal keyboard and emoji keyboard. Change this value accordingly 
         } 
    
    
        } 
    } 
    
    func keyboardWillHide(notification: NSNotification) { 
        if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() { 
         //Handle this method accordingly. For example.. 
         if(!isEmoji){     
    
          writeCommentView.frame.origin.y += keyboardSize.height 
         } 
         else{ 
          writeCommentView.frame.origin.y += 37 
         } 
        } 
    } 
    

    はそれに役立つことを願っています。

+0

おかげで私を助けたが、精のように、まだそのない完璧な方法、ユーザーがテキスト –

+0

消え提出予測オプションを開いたときに、それを扱うことができる利用可能な多くのライブラリがありますので。あなたはhttps://github.com/michaeltyson/TPKeyboardAvoidingを見ることができます – iRiziya

+0

おかげでiRiziya私はそれをチェックします –

関連する問題