は、まずあなたがあなたのWebView にscrollViewのbackroundのを追加する必要があります
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShowFunction:", name: UIKeyboardWillShowNotification, object: nil) //WillShow and not Did ;) The View will run animated and smooth
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHideFunction:", name: UIKeyboardWillHideNotification, object: nil)
()メソッドのviewDidLoad内でごViewControllersにこのコードを追加することができます。そして、あなたは時にキーボードのショーを得るためにしているが提供するこれらの二つの機能を追加する必要がありますスクロールのインセットとオフセットを変更するだけです。
func keyboardWillShowFunction(notification: NSNotification) {
if let userInfo = notification.userInfo {
if let keyboardSize: CGSize = userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue().size {
let contentInset = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0);
self.scrollView.contentInset = contentInset
self.scrollView.scrollIndicatorInsets = contentInset
self.scrollView.contentOffset = CGPointMake(self.scrollView.contentOffset.x, 0 + keyboardSize.height)
}
}
}
func keyboardWillHideFunction(notification: NSNotification) {
if let userInfo = notification.userInfo {
if let keyboardSize: CGSize = userInfo[UIKeyboardFrameEndUserInfoKey]?.CGRectValue().size {
let contentInset = UIEdgeInsetsZero;
self.scrollView.contentInset = contentInset
self.scrollView.scrollIndicatorInsets = contentInset
self.scrollView.contentOffset = CGPointMake(self.scrollView.contentOffset.x, self.scrollView.contentOffset.y)
}
}
}
Heyaご協力いただきありがとうございます。 私は上記のコードを試しましたが、それは書かれている方法では動作しません:http://zetaneon.net/share/download/XCode.png これらのすべての "自己"ステートメントはどこにでもポイントします(そして私はちょうどそれを正しく実装するためにダンプしてください)。 私はすでにコードを少し演奏していて、 "webView"ですべての "self"ステートメントを変更しようとしました。これはすでにいくつかの影響がありますが、入力が選択されると、UIWebViewが「春」になります。それとは別に、WebViewのサイズは変更されません。 ありがとうございます;) –
追加情報として、ここに問題がある可能性があるため WebViewの画面全体のサイズがあります。これは、すべての辺に0の距離を置いた拘束によって行われます。 –