Tri*_*nal 6 macos cocoa objective-c nstextview appkit
我使用自定义mouseMove事件将NSTextView光标设置为位于内容插图之外的指针。当它位于可编辑区域内时,我调用[super mouseMove]:
- (void)mouseMoved:(NSEvent*)event {
NSPoint point = [self convertPoint:event.locationInWindow fromView:nil];
if ((point.x > self.textContainerInset.width &&
point.x < self.frame.size.width - self.textContainerInset.width)
) {
[super mouseMoved:event];
} else if (point.x > 10) {
[NSCursor.arrowCursor set];
}
}
Run Code Online (Sandbox Code Playgroud)
当在文本中选择换行符(意味着行末尾的空白部分)并将鼠标悬停在所选内容上时,[super mouseMoved:event]鼠标移动的每个像素都会生成以下消息:
Appname[29357:853497] [Framework] Shared items array is empty
Appname[29357:853497] [Framework] No shared items can be accessed
Run Code Online (Sandbox Code Playgroud)
我很困惑为什么会发生这种情况,原因可能是什么?
编辑:
即使没有子类化,这似乎也会发生NSTextView。这可能是 macOS Catalina 中的一个错误。对我来说,它似乎不会造成任何其他问题。
小智 0
我找到了解决方案。它与子类化的标准建议相冲突。但据我所知,它不会引入任何不需要的行为。子类化您的 NSTextView 并重写此方法(是的,无需调用超类,这是使解决方案起作用的部分,叹息):
override func mouseMoved(with event: NSEvent) {} // swift
| 归档时间: |
|
| 查看次数: |
481 次 |
| 最近记录: |