问题描述
我一直在为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.
,由继承,以下函数:
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自定义键盘发送图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!