[英]How can I get notified of a system time change in my Cocoa application?
[英]In a Cocoa Application for macOS, is it possible to get notified during a selection change and not only at the end of the change?
我想连续跟踪 NSTextView 的选择,但我只有在选择完成更改时才成功获得更改:
- (void)textViewDidChangeSelection:(NSNotification *)notification {
}
有没有办法持续跟踪选择的变化? 任何帮助是极大的赞赏。 谢谢
我通过子类化 NSTextView 并重写以下方法成功地解决了这个问题:
-(void)setSelectedRanges:(NSArray<NSValue *> *)selectedRanges affinity:(NSSelectionAffinity)affinity stillSelecting:(BOOL)stillSelecting {
[super setSelectedRanges:selectedRanges affinity:affinity stillSelecting:stillSelecting];
if (stillSelecting && [self delegate] && [[self delegate] respondsToSelector:@selector(textViewDidChangeSelection:)]) {
NSNotification *note = [[NSNotification alloc] initWithName:@"TextViewSelectionIsChangingNotification" object:self userInfo:nil];
[[self delegate] textViewDidChangeSelection:note];
}
}
在我看来,这是一个很好的解决方案,效果很好。 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.