iOS 8 custom keyboard extension UIKeyboardType

℡╲_俬逩灬. 提交于 2019-12-22 08:22:52

问题


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);
}

回答1:


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);

}



回答2:


(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.



来源:https://stackoverflow.com/questions/26579056/ios-8-custom-keyboard-extension-uikeyboardtype

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!