如何判断我的NSScrollView当前是否正在滚动? 在iOS上我可以使用委托,但尽管谷歌搜索很多,我找不到在Mac上这样做的方法。
提前致谢!
答案 0 :(得分:13)
您可以收到NSViewBoundsDidChangeNotification通知,如下所示
NSView *contentView = [scrollview contentView];
[contentView setPostsBoundsChangedNotifications:YES];
// a register for those notifications on the content view.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(boundDidChange:)
name:NSViewBoundsDidChangeNotification
object:contentView];
通知方法
- (void)boundDidChange:(NSNotification *)notification {
// get the changed content view from the notification
NSClipView *changedContentView=[notification object];
}
答案 1 :(得分:6)
从OS X 10.9开始,还有NSScrollView.willStartLiveScrollNotification
。它在用户滚动事件开始时发布在主线程上。
E.g。
NotificationCenter.default.addObserver(self, selector: #selector(scrollViewDidScroll), name: NSScrollView.willStartLiveScrollNotification, object: nil)
答案 2 :(得分:0)
我为OSX莫哈韦沙漠和雨燕5支付2美分
let nc = NotificationCenter.default
nc.addObserver(
self,
selector: #selector(scrollViewWillStartLiveScroll(notification:)),
name: NSScrollView.willStartLiveScrollNotification,
object: scrollView
)
nc.addObserver(
self,
selector: #selector(scrollViewDidEndLiveScroll(notification:)),
name: NSScrollView.didEndLiveScrollNotification,
object: scrollView
)
....
@objc func scrollViewWillStartLiveScroll(notification: Notification){
#if DEBUG
print("\(#function) ")
#endif
}
@objc func scrollViewDidEndLiveScroll(notification: Notification){
#if DEBUG
print("\(#function) ")
#endif
}