Hello, I am new to macOS development and Swift in general and am trying to animate a NSScrollview to create a pagination like effect.
NSAnimationContext.runAnimationGroup({ context in
context.duration = 2
scrollView.contentView.animator().setBoundsOrigin(NSMakePoint(0, offset))
}) {
}}
If the user now scrolls while the animation is running, the scrollview jumps around.
I want to stop the animation at the current position so there is a callback to NSScrollView.willStartLiveScrollNotification
@objc func scrollstarted() {
print("Scroll Started")
print(NSApp.currentEvent)
var val = scrollView.contentView.frame.height
var val2 = scrollView.documentView?.frame.height ?? 0;
if(scrollView.contentView.bounds.origin.y>0 && scrollView.contentView.bounds.origin.y<=(val2-val)-1 ){
//scrollView.contentView.animator().setBoundsOrigin(NSMakePoint(0, scrollView.contentView.bounds.origin.y))
scrollView.contentView.layer?.removeAllAnimations()
}
I tried now to either set a new destination bound or to remove all animations. But both do not change the "jumping" behavior and the animation still continues to its end.
How do I stop a running animation?
6
0
1.3k