UITextView as InputAccessoryView doesn't rende

2020-03-30 05:17发布

问题:

When showing the detail viewcontroller for the first time, the inputAccessoryView will render the text immediately, but when you go back and try it again, the text doesn't get rendered untill the animation completes.

See demo project here: https://github.com/SabatinoMasala/accessoryview-demo/

If anyone has a resolution, explanation or workaround, I'd be glad to hear it!

回答1:

I tried messing with your project and, unfortunately, I saw the same behavior that you did. This may be a bug in UIKit.



回答2:

I've been experiencing the same issue and I found a simpler workaround. It seems that this bug is related to the fact that inputAccessoryView animation is using a snapshot of the view. Forcing the snapshot appears to resolve the issue:

let _ = accessoryView.snapshotViewAfterScreenUpdates(true)


回答3:

I found a workaround for this issue, take a look at the HackFix branch of the project here: https://github.com/SabatinoMasala/accessoryview-demo/tree/HackFix

We achieve this workaround by adding a dummy textfield to the view hierarchy, which we then remove on ViewDidAppear. On ViewDidAppear we also show the InputAccessoryView, which was hidden beforehand.