创建后移动对象

时间:2014-06-23 18:17:05

标签: ios objective-c

我试图在创建后移动UIImageView对象,但似乎在完成此操作时遇到问题。实际创建的图像工作正常。这是我到目前为止的代码:

    //SPAWNING RANDOM OBJECTS


    -(IBAction)spawn{

    spawn = [NSTimer scheduledTimerWithTimeInterval:1.0f
                                                        target:self
                                                      selector:@selector(spawnMechanism)
                                                      userInfo:nil
                                                       repeats:YES];
}
-(IBAction)spawnMove{

    spawnMove = [NSTimer scheduledTimerWithTimeInterval:1.0f
                                             target:self
                                           selector:@selector(spawnMoveMechanism)
                                           userInfo:nil
                                            repeats:YES];
}




-(UIImageView *)spawnMoveMechanism:(UIImageView *)spawnGood{

    spawnGood.center =CGPointMake(spawnGood.center.x, spawnGood.center.y+100);
    NSLog(@"spawnMoveMechanism accomplished");
    return spawnGood;
}

-(void)spawnMechanism{
    timeSinceLastSpawn++;

    if(timeSinceLastSpawn >= 3)
    {
        if( arc4random() % 10 < 7 ){


            UIImageView *spawnGood;

            spawnGood=[[UIImageView alloc]initWithFrame:CGRectMake(arc4random() % 700, 50, 70,70)];
            UIImage *image;
            image=[UIImage imageNamed:@"friendly-01"];
            [spawnGood setImage:image];
            [self.view addSubview:spawnGood];
             NSLog(@"spawnGood spawned");
            [self spawnMoveMechanism]; 





        }
    }
}

是否有人能够建议解决方案?提前致谢

0 个答案:

没有答案