done button only for numberpad keyboard

后端 未结 3 1823
生来不讨喜
生来不讨喜 2020-12-18 14:44

I am working on the iPhone application. I have four textfields in one of the view. In these four textfield I have one textfield in which there will be use of numberpad keybo

3条回答
  •  臣服心动
    2020-12-18 15:37

    Please please please please please please please please please please please please please do not do this. This is so ridiculously fragile. Consider this:

    • what if the layout of the number keypad changes?
    • what if the colors of the keys change?
    • what if the implementation of the keyboard changes such that it's no longer the window at index 1?
    • what if the implementation of the keyboard and peripheral host change such that introspecting the description breaks?
    • what if you're running this on iPad where the keyboard has a totally different layout?

    These are just a couple of the myriad of problems that come with glomming your UI into private view hierarchies.

    DON'T DO THIS.

    Here are 2 alternatives instead:

    1. Use the -inputAccessoryView property on every UIResponder (and thus every UIView) to define a UIToolbar with a "Done" button. The inputAccessoryView will be positioned above the keyboard as the keyboard animates in and out.

    2. Add a transparent UIView over your entire UI that captures tap events and causes the keyboard to dismiss

提交回复
热议问题