开发者

A question about CABasicAnimation

开发者 https://www.devze.com 2023-03-09 09:02 出处:网络
- (IBAc开发者_运维百科tion) showCurrentTime : (id) sender { NSLog(@\" --- showCurrentTime called --- \");
- (IBAc开发者_运维百科tion) 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"];

}

Consider the above sample code :

The above code sample compiles with absolutely no errors and warnings, but the "timeLabel", which is expected to spin 360 degrees in 1 second does not move at all. Have checked that the method "showCurrentTime" has indeed been called from the console's NSLog() output. The above method has been tested on both the phone simulator and the real device. The same problem comes up - everything is ok except no spin ... Please help.


try [CABasicAnimation animationWithKeyPath : @"transform.rotation"];

you forgot the "i" in rotation :)

0

精彩评论

暂无评论...
验证码 换一张
取 消