我有一个NSScrollView
子类,我想更新另一个NSView
基于当前滚动位置。我尝试了 KVC-观察value
of [self horizontalScroller]
但这永远不会被调用。
// In awakeFromNib
[[self horizontalScroller] addObserver:self
forKeyPath:@"value"
options:NSKeyValueObservingOptionNew
context:NULL];
// Later in the file
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context {
if (object == [self horizontalScroller] && [keyPath isEqualToString:@"value"]) {
// This never gets called
}
}
您是否发现我的推理有错误,或者知道如何观察滚动的更好方法NSScrollview
?
告诉滚动视图的内容视图发布边界更改通知,然后监听 NSViewBoundsDidChangeNotification。
[[aScrollView contentView] setPostsBoundsChangedNotifications:YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(boundsDidChangeNotification:)
name:NSViewBoundsDidChangeNotification
object:[scrollView contentView]];
如中所述滚动视图编程指南,您可以通过以下方式获取当前滚动位置:
NSPoint currentScrollPosition = [[theScrollView contentView] bounds].origin;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)