1
我做了一个程序,在屏幕顶部的随机x坐标处生成图像。图像然后落到底部。但是,我希望每隔几秒钟不断生成新的图像(同一图像),以便仿佛同一图像的这些副本从顶部持续“下雨”。循环多种方法
我该如何让这些代码每0.5秒重复一次?
@implementation ViewController {
UIImageView *_myImage;
}
- (void)viewDidLoad
{
srand(time(NULL));e
int random_x_coordinate = rand() % 286;
CGRect myImageRect = CGRectMake(random_x_coordinate, 0.0f, 40.0f, 40.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"flake.png"]];
myImage.opaque = YES;
[self.view addSubview:myImage];
_myImage = myImage;
//FALLING BIRDS TIMER
moveObjectTimer = [NSTimer scheduledTimerWithTimeInterval:0.001 target:self selector:@selector(moveObject) userInfo:nil repeats:YES];
}
//FALLING BIRDS MOVER
-(void) moveObject { // + means down and the number next to it is how many pixels y moves down per each tick of the TIMER above
_myImage.center = CGPointMake(_myImage.center.x, _myImage.center.y +1);
}
检查您是否可以使用动画来创建秋季效果。您可能需要在for循环中创建UIImageView,以便为多个图像执行此操作,然后将其存储在数组中或进行动画处理。 – iDev