使用iOS 8自定义键盘发送图像? [英] Sending images with iOS 8 custom keyboard?

查看:189
本文介绍了使用iOS 8自定义键盘发送图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在为iOS 8开发自定义键盘,但在尝试使用键盘发送图像时遇到了问题。我做了一些研究,似乎没有一种简单的方法可以用 UITextDocumentProxy 来做到这一点,因为只有 NSStrings 是允许。

I've been developing a custom keyboard for iOS 8, but stumbled upon a problem trying to send images using the keyboard. I did some research and it seems like there isn't a simple way to do this with UITextDocumentProxy because only NSStrings are allowed.

我是否忽略了使用自定义键盘发送图像的简单方法和/或有没有办法解决这个问题?

Am I either overlooking any simple ways to use a custom keyboard to send images and/or is there any way to work around this issue?

提前致谢

推荐答案

显然,你不是唯一一个尝试这样的键盘的人。如果您查看网站上的动画GIF,键盘会使用复制/粘贴将图像添加到消息中。

Apparently, you are not the only person to try a keyboard like this. If you look at the animated GIF on the site, the keyboard uses copy/paste to add the image to the messages.

UIKeyInput Protocol ,由 UITextDocumentProxy 继承,以下函数:

The UIKeyInput Protocol, which is inherited by UITextDocumentProxy, has the following function:

func insertText(_ text: String)     //Swift
- (void)insertText:(NSString *)text //ObjC

正如您所知,这些只接受String或NSString。因为没有其他方法可以插入内容,所以可以假设目前没有其他方法。

These only take a String or an NSString, as you already know. Because there are no other methods to insert content, it can be assumed that, currently, there is no other way.

现在,我建议你采用类似的方式用法。当用户点击图像时,将其添加到UIPasteboard。也许在键盘上方放置一个小横幅,上面写着你现在可以粘贴等等,但这取决于你自己决定。

Right now, I would suggest that you adopt a similar usage. When the user taps on the image, add it to the UIPasteboard. Maybe present a little banner on top of the keyboard saying, "You can now paste" or something, but that would be up to you to decide.

这篇关于使用iOS 8自定义键盘发送图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆