Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
触摸只读UITextView时,关闭iPhone数字键盘_Iphone_Ios_Xcode_Uitextview - Fatal编程技术网

触摸只读UITextView时,关闭iPhone数字键盘

触摸只读UITextView时,关闭iPhone数字键盘,iphone,ios,xcode,uitextview,Iphone,Ios,Xcode,Uitextview,在我的简单iPhone应用程序中,我有一个用于输入文本的UITextField和用于结果的UITextView。UITextField使用数字键盘,因为只允许数字。UITextView为只读,但已启用用户交互。原因是我希望用户能够进行复制和粘贴,但不改变结果。众所周知,数字键盘没有“开始”按钮。因此,我在touchesbreated中执行resignFirstResponder(),只要我在文本视图区域之外进行触摸,它就会工作。即使触摸到UITextView的内部,如何关闭键盘(数字键盘)?您可

在我的简单iPhone应用程序中,我有一个用于输入文本的UITextField和用于结果的UITextView。UITextField使用数字键盘,因为只允许数字。UITextView为只读,但已启用用户交互。原因是我希望用户能够进行复制和粘贴,但不改变结果。众所周知,数字键盘没有“开始”按钮。因此,我在touchesbreated中执行
resignFirstResponder(),只要我在文本视图区域之外进行触摸,它就会工作。即使触摸到UITextView的内部,如何关闭键盘(数字键盘)?

您可以在UITextView中添加手势识别器。未测试代码:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[self.textView addGestureRecognizer:tap];
[tap release]; // not necessary or allowed under ARC
然后处理程序:

- (void)handleTap:(UITapGestureRecognizer *)tap
{
    // resign first responder and whatever else you need to do
}

您可能需要在不需要时禁用手势识别器,如果它干扰只读
UITextView

侧注中的文本选择-某些用户可能正在使用外部键盘,因此请确保您正确验证用户在文本字段中的输入,因为这些用户将能够键入字母和其他符号。我想这可能是您需要的