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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-11-2010, 09:25 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 45
wardyfloyd is on a distinguished road
Default Randomizing

I have a button that randomizes its position when I load the app, but I need it to randomize every time I click it. right now I use this code as the x and y coordinates, and it works fine for randomizing when i first open the app.

int x1 = arc4random() % 230;
int y1 = arc4random() % 426;

also, this is the code for a timer i have for the button to pop up again.

-(void)buttonPressed1UIButton*)button {

[button setHidden:YES];
[NSTimer scheduledTimerWithTimeInterval:2
target:self selector:@selector(showButton1
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:button, @"button", nil]
repeats:NO];

}

- (void)showButton1NSTimer*)timer {
[[[timer userInfo] objectForKey:@"button"] setHidden:NO];

}

How can I make the button randomize?
wardyfloyd is offline   Reply With Quote
Old 04-11-2010, 10:06 PM   #2 (permalink)
Registered Member
iPhone Dev SDK Supporter
 
smasher's Avatar
 
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 3,858
smasher will become famous soon enough
Default

UIButton inherits from UIView, which means it has a "center" property. So you can just set that.

Code:
button.center = CGPointMake( arc4random() % 230, arc4random() % 426 );
__________________

Free Games!
smasher is offline   Reply With Quote
Old 04-13-2010, 03:33 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 45
wardyfloyd is on a distinguished road
Default

No, you misunderstood my problem. When I open my app, the buttons are in a random position, but I need them to randomize every time i click the specific buttons, not just when the application opens.
wardyfloyd is offline   Reply With Quote
Old 04-13-2010, 03:45 PM   #4 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

Have you tried using smasher's suggestion in your buttonPressed1: method?
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]
Robert Paulson is offline   Reply With Quote
Old 04-13-2010, 03:52 PM   #5 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 45
wardyfloyd is on a distinguished road
Default

Thanks, I'm new to objective c. this is a real help. while we are on this subject, if i wanted a button to be hidden when i clicked it, but i wanted it to start hidden for a certain amount of time, how would i do that?
wardyfloyd is offline   Reply With Quote
Old 04-13-2010, 06:13 PM   #6 (permalink)
A Single-Serving Friend
 
Join Date: Mar 2010
Location: Groningen, NL
Posts: 491
Robert Paulson is on a distinguished road
Default

There should be a viewDidLoad method for your view controller. You may want to set the initial setting along with a timer there. I hope this is what you were asking for.

Good luck!

edit: Alternatively, you might have to place the code in your appDelegate's applicationDidFinishLaunching method... you'll find out.
__________________
We are God’s middle children, according to Tyler Durden, with no special place in history and no special attention.

Consider saying thanks by buying my app. :]

Last edited by Robert Paulson; 04-13-2010 at 06:20 PM.
Robert Paulson is offline   Reply With Quote
Reply

Bookmarks

Tags
button, random, randomizer, timer, uibutton

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 318
15 members and 303 guests
chemistry, Domele, Fstuff, givensur, heshiming, HowEver, iAppDeveloper, iphonedevshani, jbro, JoeRCruso, kapps11, newDev, SLIC, stanny, WheyLabs
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,112
Posts: 402,874
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:26 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0