Appcelerator/ Titanium keyboard toolbar out of syn

2019-09-14 20:50发布

问题:

I have the following code:

<TextField  id="txtPhone" top="20" left="15" right="40" returnKeyType="Ti.UI.RETURNKEY_GO" keyboardType="Ti.UI.KEYBOARD_TYPE_PHONE_PAD">
        <KeyboardToolbar platform="ios">
           <Toolbar>
              <Items>
                 <Button systemButton="Titanium.UI.iOS.SystemButton.FLEXIBLE_SPACE"/>
                 <Button title="Save" systemButton="Titanium.UI.iOS.SystemButton.SAVE"/>
              </Items>
           </Toolbar>
        </KeyboardToolbar>
</TextField>

The orgional issue I had was that ios does not have a "Done" button for keyboardType="Ti.UI.KEYBOARD_TYPE_PHONE_PAD". Therefore the solution I found from other StackOverflow answers was similar to the above.

The issue is that the keyboard toolbar does not appear in sync with the keyboard.

I found a video that demonstrates this issue. https://www.youtube.com/watch?v=Cd95W1LvNXk&feature=youtu.be . However, it is quite fast on the video, so I suggest watching it at 0.25 speed.

As you can see, when closing the keyboard, the numberpad reaches the bottom of the screen faster than the keyboard toolbar.

Similarly, when opening the keyboard, the keyboard toolbar appears faster than the number pad.

How can I fix this issue?

回答1:

This is the normal behaviour of opening/closing keyboard toolbar in Titanium.

I think the toolbar animates in same duration as the keyboard takes, but the difference is of curve behaviour which is Ti.UI.ANIMATION_CURVE_EASE_OUT

Using the above fact, if you really need the same timing as of keyboard, then you can create a manual view and animate it using the same curve Ti.UI.ANIMATION_CURVE_EASE_OUT.

This is the only solution for now, but remember that doing so can cause you to do extra calculations on scrollview's scroll positions because when you will animate a manual view, then it can cover up your text-fields which are moved up by iOS itself by same amount as of keyboard height, and in some cases it might not be possible to scroll up the last textfield.

So, you will need to scroll the scrollview to adjust the textfield position (it's a lot lot more task to do, better don't mind that delay issue and stay happy :) )