Cocoa webView - 禁用所有交互 [英] Cocoa webView - Disable all interaction
问题描述
我的可可应用程序中有一个 webView(macosx 不是 iphone),它向用户显示一些 javascript,但我不希望用户能够选择任何文本或右键单击并选择重新加载选项.
I have a webView in my cocoa application (macosx not iphone), it displays some javascript to the user but I don't want the user to be able to select any of the text or right click and select the reload option.
是否有一种简单的方法可以禁用与 webView 的所有交互?
Is there a simple way to disable all interaction with the webView?
我知道在 iPhone 上禁用用户交互很容易,但我以前从未需要在桌面上执行此操作并且找不到解决方案.
I know on the iPhone its easy to disable user interaction but I have never needed to do this on the desktop before and can't find a solution.
推荐答案
同时设置编辑和 UI 委托:
Set both editing and UI delegations:
[view setUIDelegate:self];
[view setEditingDelegate:self];
然后添加上述方法以禁用文本选择和上下文菜单.
Then add the methods above to disable text selection and context menu.
- (NSArray *)webView:(WebView *)sender contextMenuItemsForElement:(NSDictionary *)element
defaultMenuItems:(NSArray *)defaultMenuItems
{
// disable right-click context menu
return nil;
}
- (BOOL)webView:(WebView *)webView shouldChangeSelectedDOMRange:(DOMRange *)currentRange
toDOMRange:(DOMRange *)proposedRange
affinity:(NSSelectionAffinity)selectionAffinity
stillSelecting:(BOOL)flag
{
// disable text selection
return NO;
}
这篇关于Cocoa webView - 禁用所有交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!