Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8894225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:26:33+00:00 2026-06-14T23:26:33+00:00

I’ve written a method, sortAndSlideHandCards(), that moves 6 UIButtons. Each UIButton is moved to

  • 0

I’ve written a method, sortAndSlideHandCards(), that moves 6 UIButtons. Each UIButton is moved to the same position. This is done via a for-each loop and the animateWithDuration method being called on each UIButton.

This method is called for a number of players at the same time. Currently the behaviour results in UIButtons from each player moving but only one at a time. No more than one UIButton can move at any time, as if each animation is waiting for whatever animation that is currently running to stop before attempting it’s own animation, essentially the code is executed sequentially for each player/UIButton. I hoped threading would help me fix this.

when I added the threading code:

backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);     
sortAndSlideHandCardsGroup = dispatch_group_create();

for(Player* player in _playersArray) {

    dispatch_group_async(sortAndSlideHandCardsGroup, backgroundQueue, ^(void) {
        [player sortAndSlideHandCards];
    });    

    dispatch_group_wait(sortAndSlideHandCardsGroup,DISPATCH_TIME_FOREVER);

I found that only the first UIButton animation is triggered for each player and that the code gets held up in the runloop “while” because “_animationEnd” never gets set as it would appear the second animation never gets going.

I can see the method launching in its own thread

- (void) sortAndSlideHandCards  {

NSLog(@"PLAYER:sortAndSlideHandCards");

CGPoint newCenter;
Card* tempCard = nil;
int count = 1;

float duration = 0.2 / _speedMultiplyer;
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
for(Card *card in _handCards) { //move cards in hand to one postion in hand

    if(count == 1) {
        tempCard = [[Card alloc] init:_screenWidth:_screenHeight :[card getNumber] :[card getCardWeight] :[card getSuit] :[card getIsSpecial]];
        [tempCard setImageSrc: _playerNumber :!_isPlayerOnPhone :count : true :_view: _isAI: [_handCards count]];
        newCenter = [tempCard getButton].center;
    }

    _animationStillRunning = true;
    if(![[DealViewController getCardsInPlayArray] containsObject:card] ) {

        [UIView animateWithDuration:duration delay:0 options:UIViewAnimationOptionLayoutSubviews animations:^{[card getButton].center = newCenter;} completion:^(BOOL finished){[self animationEnd];}];            
        while (_animationStillRunning){ //endAnimation will set _animationStillRunning to false when called
            //stuck in here after first UIButton when threading code is in play
            [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
        } //endAnimation will set _animationStillRunning to false when called

    }

    count++;
}

}

When i comment out the threading code each UIButton (Card) will animate one after another.

With the threading code is in play the first UIButton will animate but during the second run through the for-loop, the code will be stuck in the while-loop, waiting for the animation to end. I’m guessing the second animation doesn’t even start.

I also tried this for the threading code:

[player performSelectorInBackground:@selector(sortAndSlideHandCards) withObject:nil];

Same outcome

Anyone have any ideas why animateWithDuration doesn’t like getting called in a loop when in a thread other than the main one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:26:34+00:00Added an answer on June 14, 2026 at 11:26 pm

    You should just be able to kick off the animations you want from whatever UI action is performed. The UIView animateWith… methods return immediately, so you don’t need to worry about waiting for them to complete.

    If you have an unknown number of animations to kick off sequentially, use the delay parameter. Pseudocode:

    NSTimeInterval delay = 0;
    NSTimeInterval duration = 0.25;
    
    for (UIView *view in viewsToAnimate)
    {
        [UIView animateWithDuration:duration delay:delay animations:^{ ... animations ...}];
        delay += duration;
    }
    

    This will increase the delay for each successive animation, so it starts at the end of the previous one.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.