iOS:自定义键盘:我想将图像发送到 textDocumentProxy(输入控件)

时间:2023-01-31
本文介绍了iOS:自定义键盘:我想将图像发送到 textDocumentProxy(输入控件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在实现只有图像的自定义键盘,并希望在单击图像时将图像发送到 textDocumentProxy/input 控件,例如 textview,但不能克服它.到目前为止,我能够将文本/字符串发送到输入控件,但不能发送图像.

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. 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.

推荐答案

下面是复制图片到粘贴板

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://warp.povusers.org/images/test.png"]];
UIPasteboard *pasteBoard=[UIPasteboard generalPasteboard];
[pasteBoard setData:data forPasteboardType:@"public.png"];

现在的想法是,在该布局中创建自定义键盘的扩展,您可以将 UIButton 和该按钮操作实现放在 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.

对于本地图像,以下代码对您很有帮助,并且在我的情况下有效.

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.

已编辑

允许完全访问"从设置 -> 键盘 -> 键盘 -> 选择您的应用键盘 -> 在允许完全访问"的开关上

"Allow Full Access" From Settings -> Keyboard -> Keyboards -> select your app keyboard -> On switch of "Allow Full Access"

这篇关于iOS:自定义键盘:我想将图像发送到 textDocumentProxy(输入控件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:我想用蓝牙设备强制键盘打开 下一篇:键盘完成键动作swift iOS不起作用

相关文章

最新文章