iOS 8自定义键盘扩展UIKeyboardType

问题描述:

我正在构建一个iOS 8自定义键盘,我希望改变基于UIKeyboardType的键盘布局,但是,读取UIInputViewController中的键盘类型始终为0. 任何建议?提前致谢!iOS 8自定义键盘扩展UIKeyboardType

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

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

在InputView委托方法而不是ViewDidLoad中获取keyboardType。因为键盘完全显示并且输入对象被激活之前,您无法获取键盘类型。

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

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

} 

OR

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

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

} 

(没有足够的代表,以添加评论抱歉)

textDidChange是使用,因为当这就是所谓的键盘类型已更新的最佳方法。如果您使用textWillChange,则会发现键盘滞后一种类型。

+0

这帮了我!谢谢! – asetniop 2017-05-25 23:42:08