vendredi 25 décembre 2015

Randomizing position of button Obj C

Right now my code makes it so that when a user clicks Button A, Button A changes to a random position on the screen. How do I make it so that the button changes to a random position anywhere on the screen, but not go lower than the bottom portion of the screen (to allow room for a banner ad and the button not go behind the banner ad)? NOTE: the name of my button is "blackDot"

Here is what I have:

-(IBAction) mainClickButton{


int xmin = ([blackDot frame].size.width)/2;
int ymin = ([blackDot frame].size.height)/2;

int x = xmin + arc4random_uniform(self.view.frame.size.width - blackDot.frame.size.width);
int y = ymin + arc4random_uniform(self.view.frame.size.height - blackDot.frame.size.height);


    [blackDot setFrame:CGRectMake(x,y,blackDot.frame.size.width,blackDot.frame.size.height)];


}




Aucun commentaire:

Enregistrer un commentaire