2017-01-04 6 views
0

범용 iOS 앱을 개발하는 동안이 이상한 문제가 발생했습니다. 내 애플 리케이션은 오히려 간단 해 보인다. 뿌리에는 UITableViewController이 있습니다. 첫 번째 탭에는 UISplitViewController이 포함되어 있습니다. UISplitViewController의 주인은 UITableViewControllerUINavigationController이며 세부 정보는 UITableViewControllerUINavigationController입니다.UISplitViewController DetailViewController가 MasterViewController가 검색 모드에있을 때 내용이 틀립니다.

또한 마스터 테이블보기에는 항목을 필터링하는 데 사용하는 tableHeaderView에 검색 창이 있습니다. 이 모든 작품을 기대하지만 하나의 문제는 UISplitViewController가 동시에 마스터 및 세부 정보를 보여주는 장치에 나타나는 참조로 (예를 들어, 아이 패드 또는 대형 화면 아이폰 :

문제 : 키보드는 검색 창에서 활성화되면 . 마스터의, 세부의 tableView는 잘못된 contentInset.bottom

원인이 있습니다은 내가 표시 얼마나 많은 다른 세포에 따라 tableView(_:heightForRowAt:)에지도 셀 높이를 계산하기 위해 함께 tableView.bounds.heighttableView.contentInset.toptableView.contentInset.bottom를 사용

.

내가 디버그했는데 일반적으로 .top 삽입 기호는 64이고 .bottom은 49이며 이는 상태 표시 줄 + 탐색 바 및 탭바의 예상 값입니다. 그러나 키보드가 검색 창에서 활성화되어 있으면 .bottom 인세 트가 104가되어 플러스 키보드 모음의 55 개입니다. 보시다시피, 키보드 도구 모음은 tabbar를 오버레이하고 그냥 위로 이동하지 않으며 tableview가 .bottom 인세 트를 잘못 계산하고 있다고 생각합니다.

질문 : 내가 무엇을해야하므로 tableView.contentInset.bottom이 TabBar의 오버레이 도구 모음이있는 경우 TabBar의 55가있는 경우, 49에는 TabBar의이없는 경우 0이라고?

See how the map is shifted up when the keyboard toolbar is enabled?

키보드 도구 모음을 사용하는 경우지도가 이동하는 방법을 알아보십시오? tableView(_:heightForRowAt:)tableView.contentInset.bottom 104 대신 55

Does not happen when the keyboard is not active

키보드가 활성화되지 않은 경우/검색 창 집중되지의 tableView.contentInset.bottom는 49

답변

0

의 정확한 높이를 반환하기 때문이다 업데이트

IQKeyboardManager에 버그가 있음이 드러났습니다. 라이브러리를 최근에 업데이트 한 후에는 모든 것이 정상으로 돌아가고 키보드 알림을 전혀 처리하지 않아도 예상대로 작동했습니다.

func viewDidLoad(){ 
    ... 
    let center = NotificationCenter.default 
    center.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: .UIKeyboardWillShow, object: nil) 
    center.addObserver(self, selector: #selector(keyboardWillHide(_:)), name: .UIKeyboardWillHide, object: nil) 
} 

func keyboardWillShow(_ notification: Notification) { 
    guard let userInfo = notification.userInfo else { return } 
    guard let endFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else { return } 
    let duration:TimeInterval = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0 
    let animationCurveRawNSN = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber 
    let animationCurveRaw = animationCurveRawNSN?.uintValue ?? UIViewAnimationOptions.curveEaseInOut.rawValue 
    let animationCurve:UIViewAnimationOptions = UIViewAnimationOptions(rawValue: animationCurveRaw) 

    self.keyboardHeight = endFrame.size.height 
    self.tableView.contentInset.bottom = endFrame.size.height 
    self.tableView.scrollIndicatorInsets.bottom = endFrame.size.height 

    let animations:() -> Void = { 
     self.tableView.beginUpdates() 
     self.tableView.endUpdates() 
     self.view.layoutIfNeeded() 
    } 

    UIView.animate(withDuration: duration, 
        delay: TimeInterval(0), 
        options: animationCurve, 
        animations: animations, 
        completion: nil) 
} 

func keyboardWillHide(_ notification: Notification) { 
    guard let userInfo = notification.userInfo else { return } 
    let duration:TimeInterval = (userInfo[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber)?.doubleValue ?? 0 
    let animationCurveRawNSN = userInfo[UIKeyboardAnimationCurveUserInfoKey] as? NSNumber 
    let animationCurveRaw = animationCurveRawNSN?.uintValue ?? UIViewAnimationOptions.curveEaseInOut.rawValue 
    let animationCurve:UIViewAnimationOptions = UIViewAnimationOptions(rawValue: animationCurveRaw) 

    self.keyboardHeight = 0.0 
    self.tableView.contentInset.bottom = 49.0 
    self.tableView.scrollIndicatorInsets.bottom = 49.0 

    let animations:() -> Void = { 
     self.tableView.beginUpdates() 
     self.tableView.endUpdates() 
     self.view.layoutIfNeeded() 
    } 

    UIView.animate(withDuration: duration, 
        delay: TimeInterval(0), 
        options: animationCurve, 
        animations: animations, 
        completion: nil) 

} 
:

ORIGINAL 답변

나는이 같은 tableViews scrollViewInsetscontentInsets을 UIKeyboard 알림에 등록하고 수동으로 변경하여이 문제를 해결하기 위해 관리