简体   繁体   English

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

[英]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.

相关问题 如何在textDocumentProxy中使用自定义键盘扩展iOS 8设置图像? - How can I set image in textDocumentProxy with custom keyboard extension iOS 8? textDocumentProxy insertText在自定义键盘扩展中不起作用 - textDocumentProxy insertText is not working in custom keyboard extension 使用iOS 8自定义键盘发送图像? - Sending images with iOS 8 custom keyboard? 想要在键盘控件中添加完成按钮以隐藏 ios 中的键盘 - want to add done button in keyboard controls to hide keyboard in ios UITextView自定义输入(无键盘)iOS - UITextView custom input (No keyboard) iOS iOS键盘:textDocumentProxy.documentContextBeforeInput.isEmpty意外返回Nil(不应该) - iOS Keyboard: textDocumentProxy.documentContextBeforeInput.isEmpty Unexpectedly Returning Nil (when it shouldn't) 如何使用自定义键盘iOS发送图像 - How to send an image with custom keyboard iOS iOS 自定义键盘有另一个我不想附加到它的东西 - iOS custom keyboard has this other thing I don't want attached to it 检查输入文本在iOS 8的自定义键盘中是否为空 - Check if input text is empty in custom keyboard for iOS 8 如何使用Storyboard或Xib将iOS自定义键盘扩展用作Swift中的可编程自定义输入视图 - How do I use a iOS custom keyboard extension as a programmable custom input view in Swift using storyboards or xibs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM