2016-11-23 1 views
0

내보기 컨트롤러에 팝업이 표시되고 팝업에 tableview와 텍스트 필드가 포함되어 있으므로 텍스트 필드를 클릭 할 때 팝업 높이가 동일하게 유지됩니다. 그래서 나는 텍스트 필드를 클릭했을 때 내 팝업보기의 높이를 줄이려고합니다. 아무도 나를 도울 수 없습니까?키보드가 나타날 때 팝업 높이를 줄이는 방법은 무엇입니까?

+1

UITextField – ashmi123

+1

의 textfieldbegin 메소드에서 popUp보기의 프레임을 설정할 수 있습니다. 키보드가 나타나면 팝업을 위로 이동해야합니다. 키보드가 닫히면 팝업을 실제 위치로 재설정하십시오. – Sommm

답변

0

그냥 두 당신은 키보드가 나타날 때 관리 코드를 시도 알림 통지를 자동

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

Dear .. 고맙습니다. 제대로 작동하고 있습니다. 내 경우에는 내가 바꾸어야하는 유일한 것은 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 
     } 
    } 
관련 문제