I have an array containing images that I want displayed onto my view. I have a loop that goes through my array and picks a random image, then displays the image in a random position on my view. Each image has a "value" and the loop runs until a total "value" of 50 is reached.
My problem is, I do not want my images to touch each other or stack on top of each other. I have used google and youtube and various other coding help sites and for some reason cannot find a solution that fits my needs.
Code
-(void)randomizeImages {
//get random number
int randomImgNum = arc4random_uniform(5);
//use random number to get an image from array
UIImage *tempImg = [_imageArray objectAtIndex:randomImgNum];
//add UIImage to a UIImageView and place it on screen somewhere
UIImageView *tempImgView = [[UIImageView alloc] initWithImage:tempImg];
//define the center points
tempImgView.center = CGPointMake(arc4random() % 320,arc4random() % 480);
[self.view addSubview:tempImgView];
//increment count
myImgCount = myImgCount+(randomImgNum+1);
//check count
if (myImgCount<50) {
[self randomizeImages];//do it again if not yet at 50
}
}
I was going to include a screenshot but apparently I need 10 reputation before I can. I have searched everywhere for help, and posted this question a few days ago but the code that was suggested kept giving me a szone_malloc_should_clear + 14
error and I have no idea what this means or how to fix it. The question topic is dead and I really need help solving this issue.