- (IBAction) showCurrentTime : (id) sender
{
NSLog(@" --- showCurrentTime called --- ");
NSDate *now = [NSDate date];
static NSDateFormatter *formatter = nil;
if (!formatter)
{
formatter = [[NSDateFormatter alloc] init];
[formatter setTimeStyle : NSDateFormatterLongStyle];
}
[timeLabel setText : [formatter stringFromDate : now]];
// Create a basic animation
CABasicAnimation *spin =
[CABasicAnimation animationWithKeyPath : @"transform.rotaton"];
// set transform values
[spin setFromValue : [NSNumber numberWithFloat : M_PI * 0.0]];
[spin setToValue : [NSNumber numberWithFloat : M_PI * 2.0]];
[spin setDuration : 1.0];
// Add animation object to the layer
[[timeLabel layer] addAnimation : spin
forKey : @"spinAnimation"];
}
考虑以上示例代码的一个问题:约CABasicAnimation
上述代码样品与绝对没有错误和警告编译,但“timeLabel”,这是预期到旋转360度在1秒内不移动。已经确认方法“showCurrentTime”确实是从控制台的NSLog()输出中调用的。上述方法已经在手机模拟器和真实设备上进行了测试。同样的问题出现 - 一切都很好,除了没有旋转...请帮助。
你试过旋转比360以外的东西“我”?您可能会看到您正在开始的同一个地方结束,并未能通过该动作到达目的地。 – Dancreek 2011-05-31 22:33:45
已经试过M_PI * 1.0,但仍然没有动... – Stanley 2011-05-31 22:36:50
感谢您的评论,刚试过没有M_PI(如果它是0),但仍然没有“旋转”... – Stanley 2011-05-31 22:45:21