激活iPhone键盘

jcb*_*344 2 iphone keyboard cocoa-touch

我不能相信,我一直没能找到任何这还文档,但我想知道如何指挥键盘来激活并接收输入.所有的例子我能找到其中的操作,将弹出因为文本字段的了键盘进行编辑.谢谢

mto*_*toy 5

您还可以使用UIKeyInput协议来请求键盘,而无需创建隐藏文本字段.

@interface My : UIViewController <UIKeyInput> ...
Run Code Online (Sandbox Code Playgroud)

然后在实现中这样的事情

// Methods which make the keyboard work

- (BOOL) hasText
{
    return YES;
}

- (void)deleteBackward
{
    [self handleBackspace];
}

- (void) insertText:(NSString* )text
{
    int n = [text length];
    int i;
    for (i = 0; i < n; i++)
    {
        [self handleKey:[text characterAtIndex:i]];
    }
}

- (BOOL) canBecomeFirstResponder
{
    return YES;
}

// Methods to manage the appearance of the keyboard

- (void) summonKeyboard
{
    [self becomeFirstResponder];
}

- (void) dismissKeyboard
{
    [self resignFirstResponder];
}
Run Code Online (Sandbox Code Playgroud)