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 /swift5の私の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
}