iOS 8 custom keyboard extension UIKeyboardType

2019-05-07 08:48发布

I'm building a iOS 8 custom keyboard and I'd like the change the layout of the keyboard based on the UIKeyboardType, however, reading the keyboard type in UIInputViewController is always 0. Any suggestions? Thanks in advance!

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"TextInputMode: %ld", self.textDocumentProxy.keyboardType);
}

2条回答
做个烂人
2楼-- · 2019-05-07 09:16

(not enough rep to add a comment sorry)

textDidChange is the best method to use because the keyboardType has been updated when this is called. If you use textWillChange you will find that your keyboard lags behind by one type.

查看更多
一纸荒年 Trace。
3楼-- · 2019-05-07 09:22

Get the keyboardType in InputView Delegate Methods Instead of ViewDidLoad . Because you can't get the keyboardType until The keyboard is fully presented and the input object is activated .

- (void)textWillChange:(id<UITextInput>)textInput {

    NSLog(@"TextInputMode: %ld", self.textDocumentProxy.keyboardType);

}

OR

- (void)textDidChange:(id<UITextInput>)textInput {

    NSLog(@"TextInputMode: %ld", self.textDocumentProxy.keyboardType);

}
查看更多
登录 后发表回答