Quote:
Originally Posted by wardyfloyd
thanks for the advice Duncan, but I don't know if this code will transfer over from loadview to viewdidappear. how would i actually transfer this code?
|
Floyd,
You need to extract the code that changes the button's frames and put it in the -viewWillAppear method.
You should be able to leave -vewDidLoad as it is, and simply add code to -viewWillAppear that generates random numbers and applies those numbers to the frame.origin of each of your buttons.
Something like this:
Code:
- (void)viewWillAppear:(BOOL)animated
{
CGPoint newOrigin;
CGRect buttonFrame;
for (index = 0; index < button_count; index++)
{
newOrigin.x = rand() % xRange; //fix this code to set your x range
newOrigin.y = rand() % yRange; //Fix this code to set your y range
buttonFrame = button_array[index].frame;
buttonFrame.origin = newOrigin;
button_array[index].frame = buttonFrame;
}
}
That code is rough, and isn't ready to use. It assumes you have an array of button objects in button_array.
A button is a view, and a view's frame is defined in terms of it's superView (the view it's inside.) You will need to figure out the maximum and minimum origins for your buttons so that they stay inside their superview.
The view that contains the buttons will have a bounds property that gives you the rectangle the buttons should be placed inside, using the same numbering system as the frame property of each button. So you will need to juggle your button origins so their value starts at the superview's bounds.origin, and is never greater than the superview's right or bottom edges.
That should be enough guidance for you to get started. I'm under a pretty tight deadline right now, and that's the best I can give you. You're going to have to roll up your sleeves and figure out how to write this code yourself.
Regards,
Duncan C
WareTo