为什么这个iphone应用程序在我“滚动”时会滞后?

为什么这个iphone应用程序在我“滚动”时会滞后?,iphone,objective-c,uiimageview,runtime-error,lag,Iphone,Objective C,Uiimageview,Runtime Error,Lag,我正在开发一个类似涂鸦跳跃的游戏,我一次在屏幕上有5个平台。有两个背景视图。我有scrollUp功能,每当播放器位于屏幕顶部的3/4时就会调用它。当背景在视线范围内时,游戏会变慢和滞后,当背景不在视线范围内时,游戏会运行得平滑而良好。我试图禁用使它们移动的实际代码,但仍然滞后,背景图像都是我在photoshop中创建的png,并且都在单独的UIImageView中 下面是scrollUp函数代码:记住,这是objective-c在iphone上使用的Xcode: -(void)scrollUp

我正在开发一个类似涂鸦跳跃的游戏,我一次在屏幕上有5个平台。有两个背景视图。我有scrollUp功能,每当播放器位于屏幕顶部的3/4时就会调用它。当背景在视线范围内时,游戏会变慢和滞后,当背景不在视线范围内时,游戏会运行得平滑而良好。我试图禁用使它们移动的实际代码,但仍然滞后,背景图像都是我在photoshop中创建的png,并且都在单独的UIImageView中

下面是scrollUp函数代码:记住,这是objective-c在iphone上使用的Xcode:

-(void)scrollUp {
    if(fireball.center.y < scrollLine) {
    //sets up variables for background movement to add to.
    float oldXB1 = background1.center.x;
    float oldYB1 = background1.center.y;
    float oldXB2 = background2.center.x;
    float oldYB2 = background2.center.y;

         //makes "players" velocity go in the downward direction (disregard for question)
    velocity.y += .25;

    //sets up a for loop which tests each platform individually
         //[platformHolder] holds all 5 platforms
    for (int i = 0; i < [platformHolder count]; i++) {
    UIImageView *temp = (UIImageView *)[platformHolder objectAtIndex:i];
    if(fireball.center.y > 0) {
        temp.center = CGPointMake(temp.center.x, temp.center.y + 4);
    }
    if(fireball.center.y < 0) {
        temp.center = CGPointMake(temp.center.x, temp.center.y + 8);
        velocity.y += .03;
    }
    if(temp.center.y >  480) {
        scoreNum += 10;
        score.text =[NSString stringWithFormat:@"Score: %i", scoreNum];
        temp.center = CGPointMake(arc4random() % randomNumMax, 0);
    }
    }

    if(fireball.center.y > 0) {
        background1.center = CGPointMake(oldXB1, oldYB1 + velocityB1.y);
        background2.center = CGPointMake(oldXB2, oldYB2 + velocityB2.y);
    }

    if(fireball.center.y < 0) {
        background1.center = CGPointMake(oldXB1, oldYB1 + velocityB1.y);
        background2.center = CGPointMake(oldXB2, oldYB2 + velocityB2.y);
    }

    if(background1.center.y > (480 + background1.center.y/2)) {
        background1.center = CGPointMake(background1.center.x, -1*background1.center.y );
    }
    if(background2.center.y > (480 + background2.center.y/2)) {
         background2.center = CGPointMake(background2.center.x, -1*background2.center.y );
    }       
    }
}

你试过在一个单独的线程上绘制背景图像吗?在您尝试绘制背景的同时,UIScrollView可能正在尝试更新UI。如果他们在同一个线程上,那可能是延迟的原因我没有,但我会尝试一下,谢谢!老实说,这是一个非常糟糕的游戏方式。你绝对应该看看Cocos2D。ImageView并不是用来制作游戏的……这样你就可以享受OpenGL硬件加速的好处,游戏运行速度也会快得多。