WkWebView 的加载内容负责里面的导航,通常使用 javascript 或 webviews 的默认滚动行为来完成。
虽然WKWebView 是从NSView 继承的类,但你可以用它做所有超类所能做的事情。
所以你可以打电话
[self.mapview resizeSubviewsWithOldSize:NSZeroSize];
或/和
- (BOOL)canBecomeFirstResponder {
return YES;
}
可以设置。
您还可以明确定义如何处理交互。
以下示例代码旨在能够关闭 (bool)_cursor 值以停止 wkwebview 的光标交互。
#pragma mark - interaction interception
- (NSView*)hitTest:(NSPoint)point {
if (_cursor) return [super hitTest:point];
return nil;
}
- (void)keyDown:(NSEvent *)event {
[super keyDown:event];
}
- (void)keyUp:(NSEvent *)event {
[super keyUp:event];
}
-(void)mouseMoved:(NSEvent *)event {
if (_cursor) [super mouseMoved:event];
}
- (void)mouseDown:(NSEvent *)event {
if (_cursor) [super mouseDown:event];
}
- (void)mouseUp:(NSEvent *)event {
if (_cursor) [super mouseUp:event];
}
- (void)mouseDragged:(NSEvent *)event {
if (_cursor) [super mouseDragged:event];
}
- (void)mouseEntered:(NSEvent *)event {
if (_cursor) [super mouseEntered:event];
}
- (void)mouseExited:(NSEvent *)event {
if (_cursor) [super mouseExited:event];
}
但是有一个更简单的方法。
实现NSResponder协议或者Views使用对应方法时不需要UIPanGestureRecognizer..
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
// do stuff
[super touchesBegan:touches withEvent:event];
}
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
// do stuff;
}
[super touchesMoved:touches withEvent:event];
}
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
// do stuff;
}
[super touchesEnded:touches withEvent:event];
}
最后但并非最不重要..
以防万一您错过了选择器的定义
您的 WKWebView 需要以下 @implementation
-(void)panningMethod:(UIPanGestureRecognizer *)gesture {
}
通常还有 @interface 定义
-(void)panningMethod:(UIPanGestureRecognizer *)gesture;
最后,您不需要在定义 GestureRecogniser 后调用显式的 -setDelegate 方法,除非您打算为 WKWebView 设置 -navigationDelegate。