【发布时间】:2012-05-22 12:10:28
【问题描述】:
我正在创建一个游戏,其中骰子动作显示在一个圆圈中。当用户点击滚轮时,它会旋转并停在随机位置。 我搜索并找到了一些我试图实现的代码:-
[UIView beginAnimations:@"RotationAnimation" context:nil];
CALayer *myLayer = diceCircle.layer;
CABasicAnimation *fullRotationAnimation;
fullRotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotationAnimation .fromValue = [NSNumber numberWithFloat:0];
// fullRotationAnimation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotationAnimation.toValue = [NSNumber numberWithFloat:angle];
fullRotationAnimation.duration = 0.5; // speed for the rotation. Smaller number is faster
fullRotationAnimation.repeatCount = 1; // number of times to spin. 1 = once
[myLayer addAnimation:fullRotationAnimation forKey:@"360"];
[UIView commitAnimations];
角度来自:-
-(IBAction)diceButtonClicked:(id)sender
{
float angle=arc4random()%360;
NSLog(@"%f",angle);
float rad=radians(angle);
NSLog(@"%f",rad);
[self rotateDiceMethod:rad];
}
但是轮子每次都停在同一个位置,也不总是动画。请建议我一些方法或示例代码来实现所需的功能。
提前致谢!
【问题讨论】:
-
我有点困惑;是
rotateDeviceMethod:中包含的最上面的代码(动画代码)吗?
标签: ios objective-c animation uiimageview