I want a random frame.origin.x and frame.origin.y on each button click. The button need’s to move inside of the iPhone screen.
CGRect frame = MyButton.frame;
frame.origin.x = 10;
frame.origin.y = 10;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 0.1];
MyButton.frame = frame;
[UIView commitAnimations];
Does anyone know how i can generate a random number/position? Something like
frame.origin.x = frame.size.width * (arc4random() % (10 - 1)); ?
But this is moving the button outside the screen
You have to define
And get the float like:
double val = floorf(((double)arc4random() / ARC4RANDOM_MAX) * 100.0f);
More information here
http://iphonedevelopment.blogspot.com/2008/10/random-thoughts-rand-vs-arc4random.html