2016-11-23 5 views
0

私はView Controllerにポップアップを表示しています。ポップアップにはtableviewとtextfieldが含まれていますので、テキストフィールドをクリックしてもポップアップの高さは変わりません。テキストフィールドをクリックしたときに私のポップアップビューの高さを減らしたいのです。誰もこの中で私を助けてくれますか?キーボードが現れたときのポップアップの高さを減らす方法は?

+1

UITextField – ashmi123

+1

のtextfieldbeginメソッドでpopUpビューのフレームを設定すると、キーボードが表示されたときにポップアップを上に移動する必要があります。キーボードが消えたら、ポップアップを実際の位置にリセットします。 – Sommm

答えて

0

わずか2あなたはキーボードが表示されたときに管理し、このコードを試してみてください通知は、通知に自動

NotificationCenter.default.addObserver(self, selector: #selector(ClassName.keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil) 
NotificationCenter.default.addObserver(self, selector: #selector(ClassName.keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil) 

表を追加追加

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyboardWasShown), name: UIKeyboardDidShowNotification, object: nil) 
NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.keyboardWillBeHidden), name: UIKeyboardWillHideNotification, object: nil) 

// keyboard delegates method implement 
func keyboardWasShown(aNotification: NSNotification) { 
     print("Keyboard is active.") 
     // write your code that changes pop up frame. 
} 
func keyboardWillBeHidden(aNotification: NSNotification) { 
     print("Keyboard is hidden") 
     // write your code that changes pop up default frame. 
} 
+0

ありがとうございます。それは正しく働いています。私のケースでは、私が変更しなければならないのは、keyboardwillShownの通知名だけです。 –

+0

@Akashvishwakarma私たちがコードで行っていた変更を掘り下げることについては、私はちょうどあなたに後ろをつけ、その助けがあればあなたは私の答えを承認し、投票に感謝します。 –

0

のviewDidLoadで、この行を()を追加

func keyboardWillShow(notification: NSNotification) { 
     if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue { 
      UIView.animate(withDuration: 0.5) { 
var contentInsets:UIEdgeInsets 
       if (UIInterfaceOrientationIsPortrait(UIApplication.shared.statusBarOrientation)) { 
        contentInsets = UIEdgeInsetsMake(0.0, 0.0, (keyboardSize.height - (self.tabBarController?.tabBar.frame.size.height)!), 0.0); 
       } else { 
        contentInsets = UIEdgeInsetsMake(0.0, 0.0, (keyboardSize.width - (self.tabBarController?.tabBar.frame.size.width)!), 0.0); 
       } 
self.tableView.contentInset = contentInsets 
self.tableView.scrollIndicatorInsets = self.tableView.contentInset 
      } 
     } 
    } 
    func keyboardWillHide(notification: NSNotification) { 
     UIView.animate(withDuration: 0.5) { 
let contentInset:UIEdgeInsets = UIEdgeInsets.zero 
    self.tableView.contentInset = contentInset 
     } 
    } 
関連する問題