iphone - 激活 iPhone 键盘

标签 iphone cocoa-touch keyboard

我不敢相信我还没有找到任何关于此的文档,但我想知道如何命令键盘激活并接收来自它的输入。我可以找到在编辑文本字段时操作弹出键盘的所有示例。谢谢

最佳答案

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

@interface My : UIViewController <UIKeyInput> ...

然后在实现中类似这样

// 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];
}

关于iphone - 激活 iPhone 键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3098583/

相关文章:

ios - 如何将 UITableViewCell 定位在屏幕底部?

react-native - React Native - 如何仅键入数字键盘(不带标点符号)

android - 如何隐藏虚拟键盘

iphone - 动画移动和旋转 UIView 不太有效

iphone - ARC 和 ASIHTTPRequest

ios - 与 iOS 8 相比,iOS 7 使用 3x UITabBar 图标有一些奇怪的结果

iphone - Swift ResearchKit 在没有 ConsentDocument 的情况下导出答案

ios - 为@property 更改调用 UIView#setNeedsDisplay 的正确方法

iphone - NSURLConnection、NSURLRequest 和远程缓存

ios - swift : scroll the view up when keyboard shows