我创建一个的NSView,在其的drawRect方法创建并添加NSImageView作为一个子视图。

我想旋转此NSImageView(circleView),或[自]。因此,在另一种方法,我试图做到这一点:

-(void)startAnimation {
CABasicAnimation* spinAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
spinAnimation.toValue = [NSNumber numberWithFloat:5*2*M_PI];
spinAnimation.duration = 2;
[circleView.layer addAnimation:spinAnimation forKey:@"spinAnimation"];
}

然而,这种代码不会当调用该方法做任何事情。难道我做错了什么?我试图self.layer和circleView.layer但既不似乎工作...

有帮助吗?

解决方案

<击> Your're只是定义动画,你不是实际调用执行动画的动画块。

<击>

您需要调用之间限定的块:

+ beginAnimations:context:
+ commitAnimations

<击>要实际运行动画。

Edit01:我的坏。我没注意标签和添加了iPhone API的答案。

其他提示

在回答这个问题是一个NSView / NSImageView没有一个背层做动画用。

您与设置此:

[NSView setWantsLayer:YES];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top