Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by NicoVar · Oct 02, 2015 at 03:38 PM · iosinputfieldtouchscreenkeyboard

iOS TouchScreenKeyboard closes and open when tapping on another InputField

I have several InputFields on a scene. When I tap the first field, the iOS TouchScreenKeyboard popups up. When I tap any other field, the keyboard closes and opens instead of staying opened.

This is extremely annoying.

I've found no way to keep the keyboard open manually at all times, nor to avoid it being closed when an InputField looses focus.

Any ideas or workarounds?

Thanks.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by NicoVar · Oct 02, 2015 at 05:10 PM

link textI've worked around this by tapping into XCode and changing Unity's original behavior regarding UI. Not sure if this would work on other situations, but it's good enough for me.

Here's what I did:

On Keyboard.mm

1) Search for "- (void)hide" (line 229 on my case) and edit such function to add a return so its ignored, like so:

 - (void)hide
 {
     // modified by nico
     return;
     
     [self hideUI];
     _done = YES;
 }

2) Right below such function, create another with a different name:

 - (void)IA_hide
 {
     [self hideUI];
     _done = YES;
 }

3) Search for function UnityKeyboard_Hide() and above create another function like so:

 extern "C" void IA_HideTouchScreenKeyboard()
 {
     // do not send hide if didnt create keyboard
     // TODO: probably assert?
     if(!_keyboard)
         return;
     
     [[KeyboardDelegate Instance] IA_hide];
 }

4) Replace "[self hide];" with "[self IA_hide];" on the following functions: textFieldShouldReturn, textInputDone and textInputCancel.

On UnityInterface.h

5) Search for "UnityKeyboard_Hide" (line 302 on my case) and add the following row below:

 void IA_HideTouchScreenKeyboard();


On your Unity C# script (can easily be ported to JS)

6) Declare the IA_HideTouchScreenKeyboard() function at the beginning of your class:

 [DllImport ("__Internal")]
 private static extern void IA_HideTouchScreenKeyboard();

7) Then, simply call IA_HideTouchScreenKeyboard() whenever you want to close the keyboard.

Keep in mind Keyboard will not close automatically now when you, for example, tap outside the InputField. But it will close if you tap the close button on the keyboard or hit the Done button. So, you may want to call IA_HideTouchScreenKeyboard() on your InputField End Edit event, and on any other situation where you may want to close the keyboard.

I'm sure there's a much more elegant way to do this rather than simply blocking the keyboard hiding entirely, but I don't have much time and it works on my case.

Hope this helps someone.


keyboardmm.zip (5.6 kB)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by iit.vivek · May 20, 2016 at 04:05 PM

Hi @NicoVar ! Thank you so much for such a detailed solution! This was exactly what I was struggling with and your solution has almost helped me. I am just stuck at one place, as soon as I call IA_HideTouchScreenKeyboard() to close the Keyboard, my app hangs and doesn't proceed. It is just stuck.

If I don't call that function, keyboard is always visible in my app post my text input scene.

Can you help me look for what might be the issues? I am using latest Unity (5.3.4) and tested both on iOS 8.4 and 9.1.

Really appreciate your help!

Thanks Vivek

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image NicoVar · May 20, 2016 at 10:02 PM 0
Share

Hi Vivek,

That is strange. Yesterday I re-used the same approach to another project and it worked fine.

I've added the $$anonymous$$eyboard.mm file I use to the original answer above: http://answers.unity3d.com/storage/attachments/70460-keyboardmm.zip for you to compare with yours. $$anonymous$$eep in $$anonymous$$d it can differ slightly if our versions are not the same.

Try to re-check your steps and make sure you haven't forgotten anything. I didn't experience the freeze. Can you debug on XCode and see where its freezing?

avatar image iit.vivek NicoVar · May 21, 2016 at 09:16 AM 0
Share

Thanks Nico for quick response! I cleaned up the project and tried your steps again and it worked! Super helpful!

avatar image
0

Answer by icebear007 · Jun 15, 2016 at 09:18 PM

Hi,

Has anyone found a more elegant solution than this? I don't want to mess around with the mm file.

Thanks, Alex

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image karsnen · Oct 18, 2019 at 06:15 PM 0
Share

@$$anonymous$$ -> I just added another answer.

avatar image
0

Answer by karsnen · Oct 18, 2019 at 06:15 PM

Create a script (say Field.cs) that would have a text field [https://docs.unity3d.com/ScriptReference/UIElements.TextField.html] attached to it.

Now open [https://docs.unity3d.com/ScriptReference/TouchScreenKeyboard.Open.html] with the required parameters.

Once it is open, at any moment in time if you want to change the text field - just change the TextField component attached to the Field.cs

In that way, you don't have to close the TouchScreenKeyboard & just switch the text fields.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nimrodbens · Sep 01, 2020 at 06:23 PM 0
Share

can you please elaborate on it? i'm facing the same issue. i want to build a crossword app and i have multiple input fields and the keyboard opens and closes when i navigate between them.

edit: well i ended up implementing my own custom keyboard.

avatar image AdamBebko · May 10, 2021 at 05:43 PM 0
Share

Yes this answer could use some elaboration! it's not very clear what steps to take.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

37 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity 2017.3.0f3 - Input Field does not pop up TouchScreenKeyboard 0 Answers

Input field android problems 0 Answers

How to have rich text in an input field? 0 Answers

Unity 5.2.2 InputField caret bad horizontal position ios 1 Answer

How to disable native input field from Android TouchScreenKeyboard. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges