2016-12-03 59 views
1

我有一個tableView它有一個自定義inputAccessoryView,我有tableView.keyboardDismissMode設置爲.interactive。我分類UIView,我創建這個類作爲我的自定義inputAccessoryView快速問題與inputAccessoryView

在視圖中有一個textView,我自動調整大小,直到達到一定數量的行。這是我的代碼爲:

override var intrinsicContentSize: CGSize { 
    DispatchQueue.main.async { 
     let path = IndexPath(row: self.tableView.numberOfRows(inSection: 0) - 1, section: 0) 
     self.tableView.scrollToRow(at: path, at: .bottom, animated: true) 
    } 
    sendButton.frame.origin.y = self.frame.maxY - 5 - sendButton.frame.height 
    return CGSize(width: self.bounds.width, height: (textView.numberOfLines() < 10 ? textView.text.sizeForWidth(width: textView.frame.width, font: textView.font!).height : 254) + textView.frame.origin.y * 2) 
} 

func textViewDidChange(_ textView: UITextView) { 
    placeholderLabel.isHidden = !textView.text.isEmpty 
    if textView.numberOfLines() < 10 { // I defined numberOfLines() elsewhere 
     textView.isScrollEnabled = false 
    } else { 
     textView.isScrollEnabled = true 
    } 
    invalidateIntrinsicContentSize() 
} 

.async {}塊是再滾動到tableView底部一旦inputAccessoryView高度增加。

我的問題是,當我拖倒在tableView隱藏鍵盤,該tableView運行滾動動畫(那個在async塊)的時候,我不希望它滾動至底部。這裏是發生了什麼的a video

我一直在努力爭取這個工作,我想如何幾天現在。任何人都可以向我解釋爲什麼它不能像我想要的那樣工作,以及我如何解決它?

非常感謝!

+0

無關,與「視覺的限制」。 – matt

回答

2

我解決了我自己的問題!萬歲!

爲此,我在ViewController中創建了一個公共值,因爲tableView當前正在被拖動/滾動。我用UIScrollView委託方法來設置,如果tableView目前正在滾動:

scrollViewWillBeginDragging(_:) 
    and 
scrollViewDidEndDragging(_:) 

我再變intrinsicContentSize這樣:

override var intrinsicContentSize: CGSize { 
    if viewController.isDragging == false && textView.isFirstResponder { 
     DispatchQueue.main.async { 
      let path = IndexPath(row: self.tableView.numberOfRows(inSection: 0) - 1, section: 0) 
      self.tableView.scrollToRow(at: path, at: .bottom, animated: true) 
     } 
    } 
    sendButton.frame.origin.y = self.frame.maxY - 5 - sendButton.frame.height 
    return CGSize(width: self.bounds.width, height: (textView.numberOfLines() < 10 ? textView.text.sizeForWidth(width: textView.frame.width, font: textView.font!).height : 254) + textView.frame.origin.y * 2) 
} 
+0

嗨,我有擴展我的自定義inputAccessoryView到一定的限制的麻煩。我們想要實現的模式與iOS應用中的WhatsApp,iMessage,Skype等類似。如果您可以提供任何幫助或指導來幫助我實現這一目標,那將不勝感激。謝謝!! –