Made ios hideKeyboard function more robust