Mar*_*ino 4 macos cocoa objective-c
我认为这应该很简单,但是我无法使其工作。
我想检测WebView上的鼠标单击...
我将WebView细分为以下代码
#import <AppKit/AppKit.h>
#import <Foundation/Foundation.h>
#import <WebKit/WebKit.h>
@interface ResultsWebView : WebView {
}
@end
Run Code Online (Sandbox Code Playgroud)
和
#import "ResultsWebView.h"
@implementation ResultsWebView
- (void)mouseDown:(NSEvent *)theEvent {
NSLog(@"%@", theEvent);
}
@end
Run Code Online (Sandbox Code Playgroud)
在我的xib文件中,添加了WebView,然后将类更改为ResultsWebView。
我已经检查了运行时,该对象是一个ResultsWebView,但是从来没有调用mouseDown事件。
我想念什么?
假设您在NSWindowController中有一个WebView实例:
WebView *aWebView;
Run Code Online (Sandbox Code Playgroud)
您可以将控制器设置为UIDelegate,如下所示:
[aWebView setUIDelegate:self];
Run Code Online (Sandbox Code Playgroud)
在控制器中实现以下方法,您将具有对鼠标单击事件的一种控制形式:
- (void)webView:(WebView *)sender mouseDidMoveOverElement:
(NSDictionary *)elementInformation modifierFlags:(NSUInteger)
modifierFlags
{
if ([[NSApp currentEvent] type] == NSLeftMouseUp)
NSLog(@"mouseDown event occurred");
}
Run Code Online (Sandbox Code Playgroud)
作为奖励,使用elementInformation字典,您可以获得有关发生单击事件的DOM元素的其他信息。
| 归档时间: |
|
| 查看次数: |
2402 次 |
| 最近记录: |