iPad: Detecting External Keyboard

后端 未结 2 1117
我寻月下人不归
我寻月下人不归 2021-02-03 13:26

My app uses a UIAccessoryView to provide additional keyboard functionality (such as forward/backward tabs and arrows keys) for the virtual keyboard, but that causes

2条回答
  •  情歌与酒
    2021-02-03 14:31

    (This answer was suggested by Sean Heber on the Apple forums)

    When you get a UIKeyboardDidShowNotification, instead of using the frame given by UIKeyboardFrameEndUserInfoKey, simply test where the view's accessory view is and use that, instead. All I do is check to see what the frame of the accessory view is and convert it to my own view's coordinate space. Then I can easily use that frame to decide what to do.

    Note: When the on-screen keyboard is shown/hidden using the bluetooth keyboard's eject button, it seems that UIKit sends UIKeyboardDidShowNotification again but not a UIKeyboardWillHideNotification. This is also a confusing inconsistency, but the above workaround is still valid as the system will change the frame of the inputAccessoryView when it slides in the on-screen keyboard, so you can still adjust things accordingly.

提交回复
热议问题