Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 03-20-2010, 08:39 PM   #10 (permalink)
Duncan C
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 5,989
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by wardyfloyd View Post
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
Duncan C is online now   Reply With Quote
 

» Advertisements
» Online Users: 582
12 members and 570 guests
BrianSlick, coreyb, croy1, dbramhall, Duncan C, jbro, jeroenkeij, Kieren Harrold, masc2279, sacha1996, schmallegory, smithdale87
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,548
Threads: 94,073
Posts: 402,703
Top Poster: BrianSlick (7,990)
Welcome to our newest member, mrtdmb
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:28 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.