gpt4 book ai didi

ios - 如何在 uiwebview 中选择文本时禁用复制共享选项?但是选择文本应该可以

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:56:39 25 4
gpt4 key购买 nike

我想限制用户在 UIWebView 中复制和共享文本。

我使用的代码是

- (void)viewDidLoad {
[super viewDidLoad];
self.webview.delegate = self;
NSString *path = [[NSBundle mainBundle] pathForResource:@"SampleHTML" ofType:@"html"];
NSString *htmlContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
[self.webview loadHTMLString:htmlContent baseURL:[NSURL URLWithString:@""]];

// Do any additional setup after loading the view, typically from a nib.

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:))
return NO;

else if (action == @selector(select:))
return YES;

return [super canPerformAction:action withSender:sender];
}

最佳答案

您需要做的第一件事是添加带有 UIWEBVIEW 子类的新类。

将此代码粘贴到您的类的 .m 文件中。

@implementation UIWebView (Additional)

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
BOOL superCanPerform = [super canPerformAction:action withSender:sender];
if (superCanPerform) {
if (action == @selector(copy:) ||
action == @selector(paste:)||
action == @selector(cut:)||
action == @selector(_share:))
{
return false;
}
}
return superCanPerform;
}

试试这个,这将隐藏所有需要的子菜单。

关于ios - 如何在 uiwebview 中选择文本时禁用复制共享选项?但是选择文本应该可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37986733/

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