I have UI tests which testing login functionality (and uses it to test other stuff), but sometimes when focus is changed from one field to another - the keyboard hides, and
inspired by real_kappa_guy s answer above, I managed to do it without restarting the simulator by checking if the keyboard is enabled and then running apple script to send the keyboard shortcut Cmd-shift-k (need to be added to pre-test action):
if test `/usr/libexec/PlistBuddy -c "Print DevicePreferences:${TARGET_DEVICE_IDENTIFIER}:ConnectHardwareKeyboard" ~/Library/Preferences/com.apple.iphonesimulator.plist` == true; then
osascript <<EOD
tell application "Simulator" to activate
tell application "System Events"
keystroke "K" using {command down, shift down}
end tell
EOD
fi