Note that there are some explanatory texts on larger screens.

plurals
  1. POAnimating NSView via NSBezierPath
    text
    copied!<p>I have some NSBezierPath, and some NSView. I want to animate this NSView and use NEBezierPath as a animation path. Creating CAKeyframeAnimation with path from UIBezierPath on IOS works fine for me, but for OSX it's not exactly the same.</p> <p>Here is the code: </p> <pre><code> self.headView = [[NSView alloc] initWithFrame:NSMakeRect(100, 100, 50, 50)]; [self.headView setWantsLayer:YES]; [self.headView.layer setBackgroundColor:[NSColor redColor].CGColor]; [self.contentView addSubview:self.headView]; NSBezierPath *path = [NSBezierPath bezierPath]; [path moveToPoint:pathStart]; [path curveToPoint:endPoint controlPoint1:[pointValue pointValue] controlPoint2:[pointValue pointValue]]; [path setLineWidth:3.0]; [[NSColor whiteColor] set]; [path stroke]; CAKeyframeAnimation *posAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"]; posAnim.path = [path quartsPath]; posAnim.duration = 1.0; posAnim.calculationMode = kCAAnimationLinear; [self.headView.layer addAnimation:posAnim forKey:@"posAnim"]; </code></pre> <p>Converting NSBezierPath to CGPathRef is from there: <a href="https://developer.apple.com/library/mac/documentation/cocoa/Conceptual/CocoaDrawingGuide/Paths/Paths.html#//apple_ref/doc/uid/TP40003290-CH206-SW2" rel="nofollow">https://developer.apple.com/library/mac/documentation/cocoa/Conceptual/CocoaDrawingGuide/Paths/Paths.html#//apple_ref/doc/uid/TP40003290-CH206-SW2</a></p> <p>But it doesn't animate at all, here is the video: <a href="http://d.pr/v/glqQ" rel="nofollow">http://d.pr/v/glqQ</a></p> <p>I don't getting what is the problem...</p> <p>P.S. I prefer Keyframe animation because I would like to add some bouncing effect latter.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload