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 6832205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:49:49+00:00 2026-05-26T22:49:49+00:00

I have an app with multiple animations that are simple, just an image moving

  • 0

I have an app with multiple animations that are simple, just an image moving from offscreen to onscreen and then back offscreen. I’m using animation blocks, and the code is like this:

void (^animationOne) (void) = ^{imageOne.center = d;};
void (^afterOne) (BOOL) = ^(BOOL f) {imageOne.center = dOrig;};
[UIView animateWithDuration:.85 delay:3 options:opts animations:animationOne completion:afterOne];

There are several others that more or less follow the same format. However, I’d like the order in which they appear to be random. Part of the problem is that both the animations and completion blocks are specific to one another, and are required, so I can’t just stick the animations in an array, shuffle it, and then use the array for the animations. Is there a way for me to randomize this using the animation blocks, and if not, is there a different way I can do this so that I can randomize the order? Thanks.

Edit: Thanks to some helpful suggestions from vikingosegundo, I’ve altered my code to look like this:

 NSArray *animationsCompletions = [NSArray arrayWithObjects:
                                  [NSDictionary dictionaryWithObjectsAndKeys:anim1,@"animation",after1, @"completion", nil],
                                  [NSDictionary dictionaryWithObjectsAndKeys:anim2,@"animation",after2, @"completion", nil],
                                  [NSDictionary dictionaryWithObjectsAndKeys:anim3,@"animation",after3, @"completion", nil],
                                  [NSDictionary dictionaryWithObjectsAndKeys:anim4,@"animation",after4, @"completion", nil],
                                   nil];

NSDictionary *animationCompletionPair = [animationsCompletions randomElement];


[UIView animateWithDuration:.85 delay:3 options:opts animations:[animationCompletionPair objectForKey:@"animation"] completion:[animationCompletionPair objectForKey:@"completion"]];
[UIView animateWithDuration:.85 delay:8 options:opts animations:[animationCompletionPair objectForKey:@"animation"] completion:[animationCompletionPair objectForKey:@"completion"]];
[UIView animateWithDuration:.85 delay:13 options:opts animations:[animationCompletionPair objectForKey:@"animation"] completion:[animationCompletionPair objectForKey:@"completion"]];
[UIView animateWithDuration:.85 delay:18 options:opts animations:[animationCompletionPair objectForKey:@"animation"]completion:[animationCompletionPair objectForKey:@"completion"]];

However, now I’m receiving a Program received signal: EXC_BAD_ACCESS error when the view with the animations tries to load, and no other information is given by the compiler. Any suggestions would be appreciated.

  • 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-05-26T22:49:50+00:00Added an answer on May 26, 2026 at 10:49 pm

    Stick the animation and completion blocks in an array (or two). Instead of shuffling the array, just pick indices at random and execute the corresponding animation blocks.

    For example, using two arrays:

    NSArray *animations = [NSArray arrayWithObjects:animation1, animation2, animation3, nil];
    NSArray *completions = [NSArray arrayWithObjects:completion1, completion2, completion3, nil];
    int i = arc4random() % 3;
    [UIView animateWithDuration:.85
                          delay:3
                        options:opts
                      animation:[animations objectAtIndex:i]
                     completion:[completions objectAtIndex:i]];
    

    If you want each animation to run only once, then create a second array of indices and initialize it with numbers from 0 to n-1. Then shuffle that array and iterate over it executing the animation for the index you find at each position.

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

Sidebar

Related Questions

I have multiple app processes that each connect to servers and receive data from
I have an app that sends multiple Ajax requests simultaneously. I was originally running
I have a Django app where multiple teams upload content that will be parsed.
I currently have an app that requires connection to a server in multiple activities.
We have multiple config files (app.DEV.config, app.TEST.config, etc) and a pre-build event that copies
I have a vector drawing app where users can draw lines using multiple quadratic
I'm building an iPad app that will have multiple paper pages and I'd like
We have a GWT app that has multiple screens, based off of a menu.
I have a python app that uses multiple threads and I am curious about
I have multiple UIView animations running in my app. They are very short, and

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.