2011-05-31 48 views
0
- (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()输出中调用的。上述方法已经在手机模拟器和真实设备上进行了测试。同样的问题出现 - 一切都很好,除了没有旋转...请帮助。

+0

你试过旋转比360以外的东西“我”?您可能会看到您正在开始的同一个地方结束,并未能通过该动作到达目的地。 – Dancreek 2011-05-31 22:33:45

+0

已经试过M_PI * 1.0,但仍然没有动... – Stanley 2011-05-31 22:36:50

+0

感谢您的评论,刚试过没有M_PI(如果它是0),但仍然没有“旋转”... – Stanley 2011-05-31 22:45:21

回答

5

尝试[CABasicAnimation animationWithKeyPath : @"transform.rotation"];

你忘了在旋转:)

+0

谢谢你的你的善意帮助。我的拼写需要改进,或者我的思想需要重新设置,或者两者兼得......谢谢! – Stanley 2011-05-31 22:55:05