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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:29:48+00:00 2026-06-07T22:29:48+00:00

I am using CABasicAnimation to move and resize an image view. I want the

  • 0

I am using CABasicAnimation to move and resize an image view. I want the image view to be added to the superview, animate, and then be removed from the superview.

In order to achieve that I am listening for delegate call of my CAAnimationGroup, and as soon as it gets called I remove the image view from the superview.

The problem is that sometimes the image blinks in the initial location before being removed from the superview. What’s the best way to avoid this behavior?

CAAnimationGroup *animGroup = [CAAnimationGroup animation];
    animGroup.animations = [NSArray arrayWithObjects:moveAnim, scaleAnim, opacityAnim, nil];
    animGroup.duration = .5;
    animGroup.delegate = self;
    [imageView.layer addAnimation:animGroup forKey:nil];
  • 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-07T22:29:51+00:00Added an answer on June 7, 2026 at 10:29 pm

    When you add an animation to a layer, the animation does not change the layer’s properties. Instead, the system creates a copy of the layer. The original layer is called the model layer, and the duplicate is called the presentation layer. The presentation layer’s properties change as the animation progresses, but the model layer’s properties stay unchanged.

    When you remove the animation, the system destroys the presentation layer, leaving only the model layer, and the model layer’s properties then control how the layer is drawn. So if the model layer’s properties don’t match the final animated values of the presentation layer’s properties, the layer will instantly reset to its appearance before the animation.

    To fix this, you need to set the model layer’s properties to the final values of the animation, and then add the animation to the layer. You want to do it in this order because changing a layer property can add an implicit animation for the property, which would conflict with the animation you want to explicitly add. You want to make sure your explicit animation overrides the implicit animation.

    So how do you do all this? The basic recipe looks like this:

    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
    animation.fromValue = [NSValue valueWithCGPoint:myLayer.position];
    layer.position = newPosition; // HERE I UPDATE THE MODEL LAYER'S PROPERTY
    animation.toValue = [NSValue valueWithCGPoint:myLayer.position];
    animation.duration = .5;
    [myLayer addAnimation:animation forKey:animation.keyPath];
    

    I haven’t used an animation group so I don’t know exactly what you might need to change. I just add each animation separately to the layer.

    I also find it easier to use the +[CATransaction setCompletionBlock:] method to set a completion handler for one or several animations, instead of trying to use an animation’s delegate. You set the transaction’s completion block, then add the animations:

    [CATransaction begin]; {
        [CATransaction setCompletionBlock:^{
            [self.imageView removeFromSuperview];
        }];
        [self addPositionAnimation];
        [self addScaleAnimation];
        [self addOpacityAnimation];
    } [CATransaction commit];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using following code to animate a view. It basically rotates the view by
I am using the following code to move a label from one position to
I want to rotate image (left and right rotation) with angle 90.I am using
I'm using CABasicAnimation and CATransaction to animate some layers in my custom UIView. However,
Using JPA, I want to select all Log objects for a specific actiontype. From
I'm using a rotation animation created with CABasicAnimation . It rotates a UIView over
Using a CSS image sprite, I'm creating an 'interactive' image where hovering over certain
Using a populated Table Type as the source for a TSQL-Merge. I want to
I'm trying to hide a CALayer after a few microseconds and I'm using CABasicAnimation
I am using this code to flip my view. but the problem is when

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.