iOS - 检测用户何时复制到剪贴板 - [UIPasteboard genericPasteboard]
使用带有一些文本的 WebView 时快速简单的问题
- 用户可以从中选择文本片段 并按我创建的 UIButton - 运行以下操作:
-(IBAction)copyToClip
{
NSString *copyClip = [UIPasteboard generalPasteboard].string;
NSLog(@"Clip = %@",copyClip);
// (works fine)
}
我想在没有 UIButton 的情况下调用相同的函数,因此当用户执行“复制”操作时,它将激活上述代码。 (我假设有一个听众)
什么是合适的听众?
quick easy question
while using a WebView with some text in it - the user can select a snippet of text from it
and press a UIButton which I created - running the following action:
-(IBAction)copyToClip
{
NSString *copyClip = [UIPasteboard generalPasteboard].string;
NSLog(@"Clip = %@",copyClip);
// (works fine)
}
I would like to call the same function without a UIButton, thus when the user did a "copy" action it will activate the above code. (I assume a listener)
what would be the appropriate listener for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 NSNotificationCenter 并注册 UIPasteboardChangedNotification:
http://developer.apple.com/library/IOs/documentation/UIKit/Reference/UIPasteboard_Class/Reference.html#//apple_ref/c/data/UIPasteboardChangedNotification
Use NSNotificationCenter and register for UIPasteboardChangedNotification:
http://developer.apple.com/library/IOs/documentation/UIKit/Reference/UIPasteboard_Class/Reference.html#//apple_ref/c/data/UIPasteboardChangedNotification
如果有人对 Xamarin/C# 版本感兴趣:
If someone is interested in the Xamarin/C# version:
Swift 5
UIPasteboard。 changedNotification
不要忘记将
@objc
添加到您的处理程序中,以便该方法对 Objective-C 选择器可见。Swift 5
UIPasteboard.changedNotification
Don't forget to add
@objc
to your handler so the method is visible to the objective-C selector.