gpt4 book ai didi

ios - 无法禁用复制 UIWebView

转载 作者:行者123 更新时间:2023-11-29 12:56:52 25 4
gpt4 key购买 nike

在我的 ViewController 的头文件中我有:

@interface CaseStudyChoiceViewController : UIViewController <UIWebViewDelegate>

@property (strong, nonatomic) IBOutlet UIWebView *myWebView;

@end

然后在ViewDidLoad方法中的.m文件中:

[_myWebView setDelegate:self];

最后:

#pragma mark - WebView Delegate Methods

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:) ||
action == @selector(paste:) ||
action == @selector(select:) ||
action == @selector(cut:) ||
action == @selector(selectAll:))
{
NSLog(@"Selector is %@", NSStringFromSelector(action));
return NO;
}
else
{
return [super canPerformAction:action withSender:sender];
}

//I tried the code below as well and got the same result
/*
UIMenuController *menuController = [UIMenuController sharedMenuController];
if (menuController)
{
[UIMenuController sharedMenuController].menuVisible = NO;
}
return NO;
*/
}

我遇到的问题是,这将不会禁用复制功能。当我运行它时,NSLog 输出是:

    2013-12-30 21:39:28.794 PCO - CLS[45238:70b] Selector is cut:
2013-12-30 21:39:28.794 PCO - CLS[45238:70b] Selector is select:
2013-12-30 21:39:28.795 PCO - CLS[45238:70b] Selector is selectAll:
2013-12-30 21:39:28.795 PCO - CLS[45238:70b] Selector is paste:

copy: 永远不会出现在 canPerformAction 方法中。关于我可以在哪里捕获它的任何想法?

这里的最终结果是,当用户在 UIWebView 中进行长触摸时,会弹出两个选项,Copy 和 Define。我只想要定义。

最佳答案

它适用于 ios 7.0 -> 9.2

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
[webView stringByEvaluatingJavaScriptFromString:
@"document.documentElement.style.webkitUserSelect='none';"];

[webView stringByEvaluatingJavaScriptFromString:
@"document.documentElement.style.webkitTouchCallout='none';"];
}

关于ios - 无法禁用复制 UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20851026/

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