如何确定我的 NSScrollView 当前是否正在滚动?在 iOS 上,我可以使用委托,但尽管谷歌搜索了很多,但我找不到在 Mac 上执行此操作的方法。
提前致谢!
如何确定我的 NSScrollView 当前是否正在滚动?在 iOS 上,我可以使用委托,但尽管谷歌搜索了很多,但我找不到在 Mac 上执行此操作的方法。
提前致谢!
您可以收到通知 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];
}
从 OS X 10.9 开始,还有NSScrollView.willStartLiveScrollNotification
. 它在用户滚动事件开始时发布在主线程上。
例如
NotificationCenter.default.addObserver(self, selector: #selector(scrollViewDidScroll), name: NSScrollView.willStartLiveScrollNotification, object: nil)
我的 OSX mojave / swift 5 两分钱
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
}