04-12-2011, 11:39 AM
#1 (permalink )
Registered Member
Join Date: Mar 2010
Location: Dubrovnik, Croatia
Posts: 22
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!
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
You should never pause the main thread. EVER. I INSIST.
04-12-2011, 11:53 AM
#3 (permalink )
Registered Member
Join Date: Jul 2010
Posts: 70
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.
04-12-2011, 12:25 PM
#4 (permalink )
Registered Member
Join Date: Mar 2010
Location: Dubrovnik, Croatia
Posts: 22
Quote:
Originally Posted by
creyon
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;
}
04-12-2011, 12:34 PM
#5 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
__________________
04-12-2011, 12:36 PM
#6 (permalink )
Registered Member
Join Date: Mar 2010
Location: Dubrovnik, Croatia
Posts: 22
Quote:
Originally Posted by
dany_dev
I know, but I musn't return before I finish the animation.
Bump
04-12-2011, 12:56 PM
#7 (permalink )
Registered Member
Join Date: Nov 2008
Posts: 864
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;
}
04-12-2011, 01:05 PM
#8 (permalink )
Registered Member
Join Date: Jul 2010
Posts: 70
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.
04-12-2011, 01:15 PM
#9 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
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 .
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» 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