我使用下面的代码来摇动视图并且它可以正常工作,现在我想摇动一个窗口我更改了两行,我用 code2 在代码中加粗但不起作用
//-------- code 1
CGFloat DegreesToRadians(CGFloat degrees)
{
return degrees * M_PI / 180;
}
NSNumber* DegreesToNumber(CGFloat degrees)
{
return [NSNumber numberWithFloat:
DegreesToRadians(degrees)];
}
---------------
[self.view setWantsLayer:YES];
CAKeyframeAnimation * animation= [CAKeyframeAnimation animationWithKeyPath:@"transform.rotation.z"];
[animation setDuration:0.04];
[animation setRepeatCount:10];
srand([[NSDate date] timeIntervalSince1970]);
float rand = (float)random();
[animation setBeginTime:CACurrentMediaTime() + rand * .0000000001];
NSMutableArray *values = [NSMutableArray array];
[values addObject:DegreesToNumber(-1)];
[values addObject:DegreesToNumber(1)];
[values addObject:DegreesToNumber(-1)];
[animation setValues:values];
[self.view.layer addAnimation:animation forKey:@"rotate"];
//-------- code 2
[self.window.animator addAnimation:animation forKey:@"rotate"];
[self.window.animator setWantsLayer:YES];