2011-05-31 45 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