我正在尝试为transform
视图的属性设置动画。这是我的代码:
CAKeyframeAnimation *shakeAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
NSArray *transformValues = [NSArray arrayWithObjects:
[NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation((3*M_PI)/8)],
[NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation(-((3*M_PI)/8))],
[NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation((3*M_PI)/8)],
[NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation(-((3*M_PI)/8))],
[NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation((3*M_PI)/8)],
[NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation(-((3*M_PI)/8))],
nil];
[shakeAnimation setValues:transformValues];
NSArray *times = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.16f],[NSNumber numberWithFloat:0.33f],[NSNumber numberWithFloat:0.49f],[NSNumber numberWithFloat:0.66f],[NSNumber numberWithFloat:0.82f], [NSNumber numberWithFloat:1.0f], nil];
[shakeAnimation setKeyTimes:times];
NSArray *timingFunctions = [NSArray arrayWithObjects:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
nil];
[shakeAnimation setTimingFunctions:timingFunctions];
shakeAnimation.fillMode = kCAFillModeForwards;
shakeAnimation.removedOnCompletion = NO;
shakeAnimation.duration = 1.0f;
[self.someView.layer addAnimation:shakeAnimation forKey:@"anim"];
出于某种原因,每当我将方法的参数设置animationWithKeyPath:
为“转换”时,都会出现错误。我已经尝试了半个小时来调试这个,但找不到错误。我最初虽然我在 UIView 的转换属性上执行不允许的动画,但我知道我可以做这样的事情:
aView.transform = CGAffineTransformMakeRotation(M_PI/2);
提前致谢。