2015-12-17 32 views
0

我知道如何檢測Swift中顯示的普通鍵盤,但我想知道是否有可能檢測到WKWebView內部的事件,因爲...如果應用程序進入後臺,輸入失去焦點,但「模糊」事件不會被觸發。從WKWebView實例中檢測事件

這個想法是,我的應用程序中有一個「導航欄」,當鍵盤被顯示時,它被推出視圖(向上),我想繼續顯示它。知道鍵盤約216px高我只是想縮小content wrapper這是flex based216px的高度,但這不是真的工作,因爲它是一個動畫,我不能真正再現,因此它是順利的。當用戶進入emoji選項卡時,我也無法檢測到。我擺脫了autocorrect,因爲我只是將其設置爲off以代表input標記。

回答

0

試試看看這個代碼。

override viewWillAppear(){ 
    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name:UIKeyboardWillShowNotification, object: nil); 
    NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide"), name:UIKeyboardWillHideNotification, object: nil); 
} 

func keyboardWillHide(){ 
    navigationController?.setNavigationBarHidden(false, animated: true) 
} 

func keyboardWillShow(notification: NSNotification) { 
    navigationController?.setNavigationBarHidden(true, animated: true) 
    var info = notification.userInfo! 
    var keyboardFrame: CGRect = (info[UIKeyboardFrameEndUserInfoKey] as! NSValue).CGRectValue() 
    // handle your layout according to frame 
}