Question:I have a CABasicAnimation moving a NSHostingView (it’s a scrolling marquee text). When the user get his mouse cursor over the view, the animation must stops and it can interact with the view.
I tried the following approaches:
As recommended by Apple documentation (https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreAnimation_guide/AdvancedAnimationTricks/AdvancedAnimationTricks.html#//apple_ref/doc/uid/TP40004514-CH8-SW14), I tried to implement the pause/resume method using the convertTime / speed = 0.
It works, the animation is paused and resumed, but while the animation is paused, the coordinates of the user clic inside the view are the one of the model layer and not the one of the presentation layer. So the click respond to where the user would have click if their was no animation.
I tried the various animation flags on my
CABasicAnimationas follow :
Not matter what I use, when the animation is removed, the view get back to it’s original position (it jumps back to it’s original position).
let animation = CABasicAnimation(keyPath: "position"); animation.duration = 10 animation.fromValue = [0, self.frame.origin.y] animation.toValue = [-500, self.frame.origin.y] animation.isCumulative = true animation.isRemovedOnCompletion = false animation.fillMode = .forwards
I tried to save the current animation value before removing by reading the presentation layer position as follow:
But this method never returns! (ie. “after” is never printed). Could it be a bug or something?
print("before") let currentPosition = layer.presentation()?.position print("after")
I’m out of idea now. If anyone has a suggestion, it would help a lot. Thanks!
layer?.presentation()?.positiondoesn’t work because
Then Method 3 works just fine.
animation.fromValue = CGPoint(x: 0, y: self.frame.origin.y) animation.toValue = CGPoint(x: -500, y: self.frame.origin.y)
If you have better answer, please add a comment about this, thank you!