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-12-2011, 11:39 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Dubrovnik, Croatia
Posts: 22
tosibamaniac is on a distinguished road
Exclamation Threads and animations

I want to pause the main thread NSThread while I animate, is there any way to do create an animation in a another thread. Also I INSIST on using this, so plese don't say me to use delegates, because that is NOT posible in this case!
tosibamaniac is offline   Reply With Quote
Old 04-12-2011, 11:40 AM   #2 (permalink)
Senior Member
iPhone Dev SDK Supporter
 
Join Date: Aug 2008
Location: Memphis, TN, USA
Age: 24
Posts: 3,983
smithdale87 is on a distinguished road
Send a message via AIM to smithdale87
Default

You should never pause the main thread. EVER. I INSIST.
smithdale87 is offline   Reply With Quote
Old 04-12-2011, 11:53 AM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 70
creyon is on a distinguished road
Default

You should find a way to 'pause' the UI in your application while your animation takes place. Pausing the main thread is not an option.
creyon is offline   Reply With Quote
Old 04-12-2011, 12:25 PM   #4 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Dubrovnik, Croatia
Posts: 22
tosibamaniac is on a distinguished road
Default

Quote:
Originally Posted by creyon View Post
You should find a way to 'pause' the UI in your application while your animation takes place. Pausing the main thread is not an option.
Ok, but here I have an problem:
Code:
-(BOOL)yesOrNo {
// I need to animate and wait for an animation
return YESorNO;
}
tosibamaniac is offline   Reply With Quote
Old 04-12-2011, 12:34 PM   #5 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

you should animate in this mode Creating Basic Animations on iPhone | Switch on the Code
__________________
dany_dev is offline   Reply With Quote
Old 04-12-2011, 12:36 PM   #6 (permalink)
Registered Member
 
Join Date: Mar 2010
Location: Dubrovnik, Croatia
Posts: 22
tosibamaniac is on a distinguished road
Default

Quote:
Originally Posted by dany_dev View Post
I know, but I musn't return before I finish the animation.

Bump
tosibamaniac is offline   Reply With Quote
Old 04-12-2011, 12:56 PM   #7 (permalink)
Registered Member
 
Join Date: Nov 2008
Posts: 864
nobre84 is on a distinguished road
Default

You can do it, but its an ugly hack. Its always best to make your UI assinchronous. This can be accomplished by doing whatever you need to do on the didStopSelector instead, and not wasting cycles waiting.
Anyway, try this ...

Code:
-(BOOL)returnYesOrNo {
waiting = YES;        // declared as ivar

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDidStopSelector:@selector(stopWaiting)];
[UIView setAnimationDelegate:self];
//stuff to animate
[UIView commitAnimations];

NSRunLoop *theRL = [NSRunLoop currentRunLoop];
while (waiting && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
return YESorNO;
}
-(void)stopWaiting {
waiting = NO;
}
nobre84 is offline   Reply With Quote
Old 04-12-2011, 01:05 PM   #8 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 70
creyon is on a distinguished road
Default

You can:
- Pause your UI before the animation starts
- start the animation but set a didStopSelector delegate like this:

Code:
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:0.3f];
	[UIView setAnimationDelegate:self];
	[UIView setAnimationDidStopSelector:@selector(animationFinished:finished:context:)];
	
//stuff
	[UIView commitAnimations];
- when the animation finishes your code will call:
Code:
- (void) animationFinished:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {}
there you can unpause your UI and continue with your app's normal flow.
creyon is offline   Reply With Quote
Old 04-12-2011, 01:15 PM   #9 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

there aren't motive to don't use
Code:
[UIView setAnimationDidStopSelector:@selector(yourAnimationHasFinished:finished:context:)];
and then inrecept the ending with
Code:
- (void)yourAnimationHasFinished:(NSString *)animationID finished:(BOOL)finished context:(void *)context;
if you like, you can create another thread, where there is a where(!myBool){ sleep(0.2);} myBool is setted to NO; and set it to YES only when animation is finished using callback, but i don't see the motive to don't just use on you main thread.
__________________

Last edited by dany_dev; 04-12-2011 at 01:19 PM.
dany_dev is offline   Reply With Quote
Reply

Bookmarks

Tags
animation, pause, sos, stop, threading

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: 360
11 members and 349 guests
dansparrow, dre, ilmman, LezB44, Nobbsy, Objective Zero, oztemel, samdanielblr, shagor012, sledzeppelin, thephotographer
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

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