我有一些NSBezierPath和一些NSView。我想将这个NSView动画化,并使用NEBezierPath作为动画路径。用IOS上的CAKeyframeAnimation路径创建UIBezierPath对我来说很好,但对OSX来说却不完全一样。
以下是代码:
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"];将NSBezierPath转换为CGPathRef是从那里:ref/doc/uid/TP40003290-CH206-SW2
但是它一点也不动,下面是视频:http://d.pr/v/glqQ
我不明白有什么问题..。
我更喜欢关键帧动画,因为我想在后加一些弹跳效果。
发布于 2013-10-22 15:38:04
确保您的headView的superview也有一个有效的层。试试这个:
self.contentView.wantsLayer = YES;
https://stackoverflow.com/questions/19519767
复制相似问题