可可:动画内容

时间:2011-03-30 18:36:10

标签: cocoa animation

我正在将一个iPhone应用程序移植到Cocoa,我发现概念不同。例如,如果我想在我的自定义活动指示器上设置动画,我可以按如下方式构建它

-(void)makeActivityIndicator
{
    NSString *str1 = [NSString stringWithFormat:@"%@/%@", 
                      [[NSBundle mainBundle] resourcePath], @"s1.png"]; 
    UIImage *s1 = [[UIImage alloc] initWithContentsOfFile:str1];

    NSString *str2 = [NSString stringWithFormat:@"%@/%@", 
                      [[NSBundle mainBundle] resourcePath], @"s2.png"];
    UIImage *s2 = [[UIImage alloc] initWithContentsOfFile:str2];

    NSString *str3 = [NSString stringWithFormat:@"%@/%@", 
                      [[NSBundle mainBundle] resourcePath], @"s3.png"];
    UIImage *s3 = [[UIImage alloc] initWithContentsOfFile:str3];

    NSString *str4 = [NSString stringWithFormat:@"%@/%@", 
                      [[NSBundle mainBundle] resourcePath], @"s4.png"];
    UIImage *s4 = [[UIImage alloc] initWithContentsOfFile:str4];

    NSString *str5 = [NSString stringWithFormat:@"%@/%@", 
                      [[NSBundle mainBundle] resourcePath], @"s5.png"];
    UIImage *s5 = [[UIImage alloc] initWithContentsOfFile:str5];

    NSString *str6 = [NSString stringWithFormat:@"%@/%@", 
                      [[NSBundle mainBundle] resourcePath], @"s6.png"];
    UIImage *s6 = [[UIImage alloc] initWithContentsOfFile:str6];

    NSString *str7 = [NSString stringWithFormat:@"%@/%@", 
                      [[NSBundle mainBundle] resourcePath], @"s7.png"];
    UIImage *s7 = [[UIImage alloc] initWithContentsOfFile:str7];

    NSString *str8 = [NSString stringWithFormat:@"%@/%@", 
                      [[NSBundle mainBundle] resourcePath], @"s8.png"];
    UIImage *s8 = [[UIImage alloc] initWithContentsOfFile:str8];

    NSString *str9 = [NSString stringWithFormat:@"%@/%@", 
                      [[NSBundle mainBundle] resourcePath], @"s9.png"];
    UIImage *s9 = [[UIImage alloc] initWithContentsOfFile:str9];

    NSString *str10 = [NSString stringWithFormat:@"%@/%@", 
                       [[NSBundle mainBundle] resourcePath], @"s10.png"];
    UIImage *s10 = [[UIImage alloc] initWithContentsOfFile:str10];

    NSString *str11= [NSString stringWithFormat:@"%@/%@", 
                      [[NSBundle mainBundle] resourcePath], @"s11.png"];
    UIImage *s11 = [[UIImage alloc] initWithContentsOfFile:str11];

    NSString *str12 = [NSString stringWithFormat:@"%@/%@", 
                       [[NSBundle mainBundle] resourcePath], @"s12.png"];
    UIImage *s12 = [[UIImage alloc] initWithContentsOfFile:str12];

    activityImageView = [[UIImageView alloc] initWithImage:s1];

    activityImageView.animationImages = [NSArray arrayWithObjects:
                                         s1,
                                         s2,
                                         s3,
                                         s4,
                                         s5,
                                         s6,
                                         s7,
                                         s8,
                                         s9,
                                         s10,
                                         s11,
                                         s12,
                                         nil];
    [s12 release];
    [s11 release];
    [s10 release];
    [s9 release];
    [s8 release];
    [s7 release];
    [s6 release];
    [s5 release];
    [s4 release];
    [s3 release];
    [s2 release];
    [s1 release];

    activityImageView.animationDuration = 1.0;  
    activityImageView.frame = CGRectMake(386 - 36, 512 - 36, 72, 72);
}

然后我可以用:

显示它
[mainView addSubview:activityImageView];
[activityImageView startAnimating];

并用

停止
[activityImageView removeFromSuperview];

Cocoa有类似的概念吗?你会指出哪个文档在哪里拼写出来?

0 个答案:

没有答案