Objective C加速动画/对象创建

时间:2009-11-03 03:12:38

标签: iphone animation

我可以使用什么样的技巧来加速和改进图像序列动画?

我正在使用下面的代码,但只需运行下面的代码需要几秒钟才能完成。

创建动画后,我的手机似乎也变慢了。

请点亮。

谢谢, 三通

    NSMutableArray * sequenceArray;
sequenceArray = [[NSMutableArray alloc] init];

int k;
int xPos = 0;
int yPos = 50;
for (k = 1; k <= 48; k++)
{
    UIImageView* dynamicView = [[UIImageView alloc] initWithFrame:self.view.frame];
    [sequenceArray addObject:dynamicView];

    int i;
    NSMutableArray *a = [NSMutableArray array];
    for (i = 1; i <= 102; i++)
    {
        [a addObject:[UIImage imageNamed:[NSString stringWithFormat:@"loop2 %d.png", i]]];
    }

    dynamicView.animationImages = a;
    //[a release];

    // all frames will execute in 1.75 seconds
    dynamicView.animationDuration = 1.6;
    // repeat the annimation forever
    dynamicView.animationRepeatCount = 0;


    CGRect frame1 = dynamicView.frame;
    frame1.size.width = 34;
    frame1.size.height = 34;
    frame1.origin.x = xPos;
    frame1.origin.y = yPos;
    dynamicView.frame = frame1;

    if (k % 8 == 0) {
        xPos = 0;
        yPos += 40;
    }

    xPos += 40;
    NSLog(@"step last");
    // start animating
    [dynamicView startAnimating];
    // add the animation view to the main window 
    [self.view addSubview:dynamicView];
    [dynamicView release];
}

1 个答案:

答案 0 :(得分:3)

那么,你创建了48个UIImageViews,每个都有相同102帧的动画?我读得对吗?

我发生的第一件事就是把它拉出另一个循环,因为它每次都加载相同的数组,并将其分配给每个视图:

    int i;
    NSMutableArray *a = [NSMutableArray array];
    for (i = 1; i <= 102; i++)
    {
            [a addObject:[UIImage imageNamed:[NSString stringWithFormat:@"loop2 %d.png", i]]];
    }

但是,真的,为什么你这样做?