0

ビューにテキスト ビューや装飾などがありますが、他のメッセージング アプリと同じように、そのビューをキーボードにドッキングさせたいと考えています。

テキストビューを表示しようとしているときに、ビューをキーボードにアタッチする方法は次のとおりです。

-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    UIView *inputView = self.textInputView; //connected at IB outlet from storyboard, also contains the text view itself.
    constraintsOfTextInputView = [self constraintsRelatedToView:inputView]; //to be able to add them again
    [[UIApplication sharedApplication].keyWindow addSubview:self.textInputView];
    textView.inputAccessoryView = inputView;
    editingTextView = textView;
    return YES;
}

そして、却下するとき:

//using notification hook for UIKeyboardWillHideNotification because
//textView[Will|Did]EndEditing is called too late

-(void)keyboardWillHide{
    if(editingTextView && constraintsOfTextInputView){
        editingTextView.inputAccessoryView = nil;
        [self.textInputView removeFromSuperview];
        [self.view addSubview:self.textInputView]; <--- EXCEPTION
        [self.view addConstraints:constraintsOfTextInputView];
        [self.view layoutIfNeeded];

        editingTextView = nil;
        constraintsOfTextInputView = nil;
    }
}

追加するときとは正反対のことをしていますが、次の例外が発生しています。

*** Terminating app due to uncaught exception
'UIViewControllerHierarchyInconsistency', reason: 'child view controller:
<UICompatibilityInputViewController: 0x13307ba20> should have parent view
controller:<ULPostViewController: 0x1307a7c00> but actual parent is:
<UIInputWindowController: 0x12f0be200>'

どうすればこの問題を解決できますか? 私は iOS 8 を使用しています (古いバージョンはサポートしていません)。

更新:問題を示す git リポジトリを作成しました:

https://github.com/can16358p/CPInputAccessoryTest

4

2 に答える 2

1

テキスト ビューをビュー コントローラー全体の入力アクセサリ ビューとして使用できます。私のプルリクエストを見てください。

拡大するテキスト ビューの部分を除いて、これはほとんどメッセージ アプリの動作です。

于 2015-06-22T11:11:59.827 に答える