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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:14:11+00:00 2026-05-29T15:14:11+00:00

I have path stored in an array of CGPoints which I’d like to move

  • 0

I have path stored in an array of CGPoints which I’d like to move an image along. Here’s the general code I have so far:

-(void)movePic:(id)sender{
    for(int i = 0; i < self.array.count; i++){
        CGPoint location = [[self.array objectAtIndex:i] CGPointValue];
        [UIView animateWithDuration:0.1 animations:^{
            self.imageView.center = location;
        } completion:^(BOOL finished){
        }];
    }
}

The problem is the for loop runs extremely fast, so you only see the animation on the last points. I’m unsure of how to better design this. Ideally, what could I do to make sure one animation finishes before the other begins? Should I not use a for loop? Thanks

  • 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-29T15:14:11+00:00Added an answer on May 29, 2026 at 3:14 pm

    Your code assumes that UIView animations run synchronously in the main thread, which they do not.

    You seem to have two options

    • Explicit CAKeyframeAnimation for animating a CALayer along any amount of sample points (interpolated between them)
    • Implicit recursive UIView animation for animating a UIView along a series of sample points (interpolated between them)

    The former would be much more efficient – still I thought I oould show you both options.

    CAKeyframeAnimation

    - (void)movePic:(id)sender
    {
        //create a mutable core-graphics path
        CGMutablePathRef path = CGPathCreateMutable();
        for(int i = 0; i < self.array.count; i++)
        {
            CGPoint location = [[self.array objectAtIndex:index] CGPointValue];
            CGPathAddLineToPoint(path, nil, location.x, location.y);
        }
        //create a new keyframe animation
        CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
        //add our path to it
        pathAnimation.path = path;
        //be nice to the system
        CGPathRelease(path);
        //setup some more animation parameters
        pathAnimation.duration = 0.1 * self.array.count;
        //add the animation to our imageView's layer (which will start the animation)
        [self.imageView.layer addAnimation:pathAnimation forKey:@"pathAnimation"];
    }
    

    UIView Animation

    - (void)movePicToPointAtIndex:(unsigned int)index
    {
        //safeguard check...
        if ([self.array count] <= index)
            return;
        //get the next location
        CGPoint location = [[self.array objectAtIndex:index] CGPointValue];
        //animate the imageView center towards that location
        [UIView animateWithDuration:0.1 
                              delay:0.0 
                            options:UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction
                         animations:^{
            self.imageView.center = location;
        } completion:^(BOOL finished){
            //we are done with that animation, now go to the next one...
            [self movePicToPointAtIndex:index+1];
        }];
    }
    
    - (void)movePic:(id)sender
    {
        [self movePicToPointAtIndex:0];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a folder path stored in the property nightly.basepath (here the value would
I have stored images from the net like this Documents/imagecache/domain1/original/path/inURI/foo.png Documents/imagecache/domain2/original/path/inURI/bar.png Documents/imagecache/... Documents/imagecache/... Now
I have stored the XML path to items in a string like this: response->items->item
I have a directory path stored in a text file, and I need to
I have a path like C:\application\photo\gallery\sketches . Now I need to check whether this
I have a path like this: parent/child/reply How do I use PHP to remove
I wanted to make an associative array in Javascript in which I would have
I have two arrays, one is a node-node-cost array [a_node,b_node,cost] which has 8000 entries
Greetings. I have an 2-D array of size [N][N] which will represent a rectangular
I have a path and I need to determine if it is a directory

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.