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 09-03-2010, 10:43 AM   #1 (permalink)
Registered Member
 
TrueScot's Avatar
 
Join Date: Oct 2009
Posts: 48
TrueScot is on a distinguished road
Default Flashing UIImage (overlaying as a pretend button)

I'm trying to use a UIImage as a button which gives the impression of it being turned on then off again within about half a second. This works fine if I switch it on but if I want to switch it off again (by including removeFromSuperview) it doesn't switch on at all. I have a short loop in there to prevent it switching on and off so fast I can't see it but it doesn't switch on at all. I've tried it with and without the [flashingButton release]. Is there something I'm misunderstanding here? Can I addSubview and removeFromSuperView at the same time even with a short delay?



if ( some conditional statements in here .......) {

UIImage *estimateButton1 = [UIImage imageNamed:@"FlashingButton.png"];
flashingButton = [[UIImageView alloc] initWithImage:flashingButton1];
flashingButton.frame = CGRectMake (146,8,165,30);
[self.view addSubview:flashingButton];
// [flashingButton release];


// short loop in here to delay turning the button off

[self.flashingButton removeFromSuperview];

Last edited by TrueScot; 09-03-2010 at 11:36 AM.
TrueScot is offline   Reply With Quote
Old 09-03-2010, 09:22 PM   #2 (permalink)
Registered Member
 
kelvinkao's Avatar
 
Join Date: Jul 2009
Location: Los Angeles
Posts: 352
kelvinkao is on a distinguished road
Send a message via AIM to kelvinkao
Default

Whoa! Please don't do something like this.

What's happening here is that you are trying to add a view. And then you have a loop to block the execution of EVERYTHING. So during that time, your app can't do anything (such as showing the view?) And then once the loop is over, you remove the view. So nothing ever shows.

When you have the loop there to waste time, nothing is getting done. This is bad, just like sleeping the main thread. What you want to do instead is add the view. And then you set an NSTimer to fire later. When it fires, you hide the view. Or you can do it with performSelector withDelay methods. Just don't block the execution of the whole app! (Because the app will freeze during that time, and when it goes on for too long, the OS will even kill it!)
__________________
My dev blog:
http://www.kelvinkaodev.com
kelvinkao is offline   Reply With Quote
Old 09-04-2010, 01:19 AM   #3 (permalink)
Registered Member
 
mouser58907's Avatar
 
Join Date: Feb 2010
Posts: 188
mouser58907 is on a distinguished road
Default

Why not just use a UIButton with an image instead of using a UIImage as a button. Also, instead of removing it from superview, if its going to come back shortly afterwords, just set hidden = YES for the button.
__________________
My Apps:Pee Prank (free)
My Company: Pulsar Productions

If I helped you, download my App or tell a friend! Thanks.
mouser58907 is offline   Reply With Quote
Reply

Bookmarks

Tags
objective c, sdk, xcode

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: 345
11 members and 334 guests
bignoggins, carlandrews, flamingliquid, ilmman, iram91419, linkmx, nadav@webtview.com, Objective Zero, Paul Slocum, stanny, v1n2e7t
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,656
Threads: 94,116
Posts: 402,889
Top Poster: BrianSlick (7,990)
Welcome to our newest member, iram91419
Powered by vBadvanced CMPS v3.1.0

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