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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:25:35+00:00 2026-05-14T03:25:35+00:00

I am starting to learn to use UIView animation. So I wrote the following

  • 0

I am starting to learn to use UIView animation. So I wrote the following lines:

[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:2.0];
[UIView setAnimationRepeatCount:2];
[UIView setAnimationRepeatAutoreverses:YES];

CGPoint position = greenView.center;
position.y = position.y + 100.0f;
position.x = position.x + 100.0f;
greenView.center = position;

[UIView commitAnimations];

In this case, the UIView (a green box) moved back and fore 2 times. So far so good, BUT I found out that after the moving twice, the green box ended up jumped to the “new position” (position.x + 100.0f, position.y + 100.0f) instead of going back to the original position (position.x, position.y). That makes the animation look pretty odd (like after the box swing back to the original position caused by setAnimationRepeatAutoreverses, it jumps back to the new position in the last microsecond!)

What is the best way to make the green box NOT jump to the new position at the very last minute?

  • 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-14T03:25:36+00:00Added an answer on May 14, 2026 at 3:25 am

    I’ve had exactly the same issue with using UIView animations on the alpha property. The worst part is that the animation jumps to the “final” position before the animationDidStop: delegate message is sent, which means you can’t manually set the original state there.

    My solution was to use the animationDidStop delegate messages to create a new animation block, and string them all together:

    - (void)performAnimation
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(phase1AnimationDidStop:finished:context:)];
    
        // Do phase 1 of your animations here
        CGPoint center = someView.center;
        center.x += 100.0;
        center.y += 100.0;
        someView.center = center;
    
        [UIView commitAnimations];
    }
    
    - (void)phase1AnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
    {
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(phase2AnimationDidStop:finished:context:)];
    
        // Do phase 2 of your animations here
        CGPoint center = someView.center;
        center.x -= 100.0;
        center.y -= 100.0;
        someView.center = center;
    
        [UIView commitAnimations];
    }
    
    - (void)phase2AnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
    {
        // Perform cleanup (if necessary)
    }
    

    You can string together as many animation blocks as you want this way. It seems wasteful code-wise, but until Apple give us a -[UIView setAnimationFinishesInOriginalState:] property or something similar, this the only way that I’ve found to solve this problem.

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

Sidebar

Related Questions

I am just starting to learn how to use RMI, and I have a
I'm starting to learn how to use Django on the Google App Engine. I
I am totally new to emacs and is starting to learn how to use
I'm just starting to learn T-SQL and could use some help in understanding what's
I'm just starting to learn AspectJ, and I have use-case for say, User login.
I am starting to learn Python, but I'm forced to use a v2.6.2 interpreter.
I am starting a new project and was going to use it learn asp.net
I'm currently starting to learn to use java to create dynamic websites. I've started
I'm starting to learn WPF and currently use Visual Studio Express 2010 at home.
I'm starting to learn strophe library usage and when i use addHandler to parse

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.