[英]iOS: Custom keyboard: I want to send images to the textDocumentProxy(Input controls)
I am implementing custom keyboard with only images and wanted to send images to textDocumentProxy/input controls like textview on click of image but not get over it. 我正在实现只有图像的自定义键盘,并希望将图像发送到textDocumentProxy /输入控件,如textview点击图像但不能克服它。 so far I am able to send text/string to input controls but not images.
到目前为止,我能够将文本/字符串发送到输入控件而不是图像。
Is it possible to send images to input controls? 是否可以将图像发送到输入控件?
Any suggestion or solution is highly appreciated. 任何建议或解决方案都非常感谢。
Following is the code for the copy image into pasteboard 以下是将图像复制到粘贴板中的代码
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://warp.povusers.org/images/test.png"]];
UIPasteboard *pasteBoard=[UIPasteboard generalPasteboard];
[pasteBoard setData:data forPasteboardType:@"public.png"];
Now the think is that create extension of custom keyboard in that layout you can put your UIButton and that button action implement above for png image. 现在的想法是在该布局中创建自定义键盘的扩展,您可以将您的UIButton和上面的按钮操作实现为png图像。
For Local Image following code is help full to you and it's working in my case. 对于本地图像,以下代码对您来说是完全有用的,它在我的情况下正常工作。
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
NSData *imgData = UIImagePNGRepresentation(@"Your UIImage Here");
[pasteboard setData:imgData forPasteboardType:[UIPasteboardTypeListImage objectAtIndex:0]];
More Uniform Type Identifiers you visit here and change Pasteboard Type. 您在此处访问的更多统一类型标识符并更改粘贴板类型。
May this help lot and solve your problem. 愿这有助于解决您的问题。
Edited 编辑
"Allow Full Access" From Settings -> Keyboard -> Keyboards -> select your app keyboard -> On switch of "Allow Full Access" “允许完全访问”来自设置 - >键盘 - >键盘 - >选择您的应用键盘 - >开启“允许完全访问”
Please try in a device, you can test with iMessage App in a device. 请尝试使用设备,您可以在设备中使用iMessage App进行测试。 Default input views like UITextView and UITextField do not support the images.
UITextView和UITextField等默认输入视图不支持图像。 They only support the strings.
他们只支持字符串。
The following code will copy the image into the pasteboard. 以下代码将图像复制到粘贴板中。
let pb = UIPasteboard.generalPasteboard()
let image: UIImage = UIImage(named: imgArray[indexPath.row])!
let imgData: NSData = UIImagePNGRepresentation(image)!
pb.setData(imgData, forPasteboardType: kUTTypePNG as String)
And give "Allow Full Access" for keyboard in settings. 并在设置中为键盘提供“允许完全访问”。 And add the
RequestsOpenAccess
to YES in the info.plist file. 并在info.plist文件中将
RequestsOpenAccess
添加到YES。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.