how can I enable keyboard when tapping a Textfield in Xcode preview. I somehow activated it and clicked some keys and then I accidentally typed a shortcut on my Mac and it disappeared.
How can I enable it again?
It turns out this setting is (very subtly) tied to the "Connect Hardware Keyboard" preference in the iOS Simulator app (found in the menu bar as I/O → Keyboard → Connect Hardware Keyboard). The keyboard will only appear in "Live Preview" mode and with this setting disabled, and Xcode will instantly reset the setting as soon as it detects any direct keyboard input while the preview has focus (and the Simulator app will not reflect this reset, so to do it again you'll have to toggle it twice). Worse, flipping the setting in the Simulator app is not enough by itself; you have to force the preview to fully reload the underlying simulator it's using. The easiest way to do this is to restart Xcode or to switch to a different simulated device (such as from iPhone 11 to iPhone 12). You can also try executing this command in a terminal:
xcrun simctl --set ~/Library/Developer/Xcode/UserData/Previews/Simulator\ Devices shutdown all
This command will not affect any simulators running in the iOS Simulator app, but will cause all previews to stop working until Xcode relaunches the simulated devices, and may cause Xcode's UI to temporarily behave strangely (or at least the effects were temporary when I tried it in Xcode 12.4).
Once the setting is in effect, focusing on a text input field will cause the software keyboard area to appear. The area is responsive to clicks and all the keys work, but the keyboard itself does not seem to render. It is obviously not intended that this works, and it may stop working at any time in the future.
This might be a bug, I tried running preview in debug mode in several cases and noticed that when a text field is tapped, console throws errors about some constraints that are not satisfied and there's no access to them.
I also enabled "Show View Frames" from Xcode's "Debug" menu, the keyboard frame actually appears on the screen but is not shown for some reason. In rare cases, the constraints error was gone for no reason and the keyboard was successfully displayed but simply restarting the preview caused it to disappear again. So this might be a bug and if so, hope this gets fixed in next releases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With