How can I find out whether my NSScrollView is currently scrolling? On iOS I can use the delegate but despite of googling a lot I can't find a way to do this on the Mac.
Thanks in advance!
How can I find out whether my NSScrollView is currently scrolling? On iOS I can use the delegate but despite of googling a lot I can't find a way to do this on the Mac.
Thanks in advance!
You can receive notification NSViewBoundsDidChangeNotification like shown below
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];
The notification method
- (void)boundDidChange:(NSNotification *)notification {
// get the changed content view from the notification
NSClipView *changedContentView=[notification object];
}
As of OS X 10.9 there is also NSScrollView.willStartLiveScrollNotification
. It's posted on the main thread at the beginning of a user scroll event.
E.g.
NotificationCenter.default.addObserver(self, selector: #selector(scrollViewDidScroll), name: NSScrollView.willStartLiveScrollNotification, object: nil)
my two cents for 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
}
© 2022 - 2024 — McMap. All rights reserved.
scrollViewDidScroll
in the past tense, but the notification namewillStartLiveScrollNotification
in the future tense? – Conaway