//******************旋转动画******************
//产生随机角度
srand((unsigned)time(0)); //不加这句每次产生的随机数不变
random = (rand() % 20) / 10.0;//设置随机角度
if ((int)(random*100)%5 == 0) {
random = random + 0.01;
}
//设置动画
CABasicAnimation *spin = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
[spin setFromValue:[NSNumber numberWithFloat:M_PI * (0.0+orign)]];
[spin setToValue:[NSNumber numberWithFloat:M_PI * (10.0+random+orign)]];
[spin setDuration:2.5];
[spin setDelegate:self];//设置代理,可以相应animationDidStop:finished:函数,用以弹出提醒框
//速度控制器
[spin setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];//加速
//添加动画
[[_backIm layer] addAnimation:spin forKey:nil];
//锁定结束位置
_backIm.transform = CGAffineTransformMakeRotation(M_PI * (10.0+random+orign));
//锁定fromValue的位置
orign = 10.0+random+orign;
orign = fmodf(orign, 2.0);
无需记录角度问题