2016-12-03 10 views
1

inputAccessoryViewtableViewがあります。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 {}ブロックはinputAccessoryView高が増加した後、再びtableViewの下までスクロールするためです。

私の問題は、私はキーボードを非表示にするtableViewを下にドラッグしたとき、私はそれが一番下までスクロールしたくないとき、tableViewはスクロールアニメーション(asyncブロック内の1)を実行していることです。ここには何が起こっているのa videoです。

私は今これを数日間したいと思うように働かせることに苦労しています。誰も私にそれをしたいと思うように動作していないと私はそれを修正することができます私に説明してくださいか?

ありがとうございます!

+0

「視覚的な制約」とは何の関係も。 – matt

答えて

2

私は自分の問題を解決しました!やめ!

tableViewが現在ドラッグ/スクロールされている場合は、ViewControllerに公開値を作成しました。私はtableViewが現在スクロールされているかどうかを設定するUIScrollViewデリゲートメソッドを使用:

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などと似ています。あなたがこれを達成するための助けや指導をすることができれば、それは非常に感謝しています。ありがとうございました!! –