Custom iPhone Keyboard

前端 未结 4 1130
情书的邮戳
情书的邮戳 2020-11-27 17:05

I need (i.e. a customer requirement) to provide a custom keyboard for the user to type text into both text fields and areas. I already have something that does the keyboard

4条回答
  •  春和景丽
    2020-11-27 17:20

    As long as you're not submitting your app to the app store, you can use a technique called method swizzling to dynamically replace methods of core classes at runtime. For example:

    @interface UIControl(CustomKeyboard)
    - (BOOL)__my__becomeFirstResponder
    @end
    
    @implementation UIControl(CustomKeyboard)
    - (BOOL)__my__becomeFirstResponder
    {
        BOOL becameFirstResponder = [self __my__becomeFirstResponder];
        if ([self canBecomeFirstResponder]) {
            [MyKeyboard orderFront];
        }
        return becameFirstResponder;
    }
    
    + (void)initialize
    {
        Method old = class_getInstanceMethod(self, @selector(becomeFirstResponder));
        Method new = class_getInstanceMethod(self, @selector(__my__becomeFirstResponder));
        method_exchangeImplementations(old, new);
    }
    @end
    

    Please don't use anything like this in any production code. Also, I haven't actually tested this, so YMMV.

提交回复
热议问题