gpt4 book ai didi

iphone - iOS - 检测用户何时复制到剪贴板 - [UIPasteboard generalPasteboard]

转载 作者:可可西里 更新时间:2023-11-01 03:08:21 24 4
gpt4 key购买 nike

简单的问题

在使用其中包含一些文本的 WebView 时 - 用户可以从中选择一段文本然后按下我创建的 UIButton - 运行以下操作:

-(IBAction)copyToClip
{
NSString *copyClip = [UIPasteboard generalPasteboard].string;
NSLog(@"Clip = %@",copyClip);
// (works fine)
}

我想在没有 UIButton 的情况下调用相同的函数,因此当用户执行“复制”操作时,它将激活上面的代码。 (我假设一个听众)

什么是合适的监听器?

最佳答案

使用 NSNotificationCenter 并注册 UIPasteboardChangedNotification: http://developer.apple.com/library/IOs/documentation/UIKit/Reference/UIPasteboard_Class/Reference.html#//apple_ref/c/data/UIPasteboardChangedNotification

[[NSNotificationCenter defaultCenter] addObserver:object selector:@selector(copyToClip) name:UIPasteboardChangedNotification object:nil];

关于iphone - iOS - 检测用户何时复制到剪贴板 - [UIPasteboard generalPasteboard],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8941860/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com