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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:33:51+00:00 2026-06-15T04:33:51+00:00

I am trying to animate a CAEmitterLayer ‘s emitterPosition like this: CABasicAnimation *animation =

  • 0

I am trying to animate a CAEmitterLayer‘s emitterPosition like this:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"emitterPosition.x"] ;
animation.toValue = (id) toValue ;
animation.removedOnCompletion = NO ;
animation.duration = self.translationDuration ;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut] ;
animation.completion = ^(BOOL finished)
    {
    [self animateToOtherSide] ;
    } ;
[_emitterLayer addAnimation:animation forKey:@"emitterPosition"] ;
CGPoint newEmitterPosition = CGPointMake(toValue.floatValue, self.bounds.size.height/2.0) ;
_emitterLayer.emitterPosition = newEmitterPosition ;

Note that animation.completion is declared in a category that just calls the corresponding CAAnimation delegate method.

The problem is that this doesn’t animate at all and shows the emitter in its final position. I was under the impression that once you add the animation to the layer, you should change the actual model behind it to its final position so that when the animation completes the model is in its final state; i.e., to prevent the animation from “snapping back” to its original position.

I have tried placing the last two lines in the animation.completion block, and this does indeed animate as expected. However, when the animation finishes some particles are intermittently emitted at the emitter’s original position. If you put the system under load (for example, scrolling a tableview while the animation is playing), this happens more often.

Another solution I was thinking about is to not move the emitterPosition at all but just move the CAEmitterLayer itself, although I haven’t tried that yet.

Thanks in advance for any help you can provide.

  • 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-15T04:33:52+00:00Added an answer on June 15, 2026 at 4:33 am

    Perhaps emitterPosition.x is not a valid key path for animation. Try using emitterPosition instead (and so you’ll have to provide CGPoint values wrapped up in an NSValue).

    I just tried this on my own machine and it works fine:

    CABasicAnimation* ba = [CABasicAnimation animationWithKeyPath:@"emitterPosition"];
    ba.fromValue = [NSValue valueWithCGPoint:CGPointMake(30,100)];
    ba.toValue = [NSValue valueWithCGPoint:CGPointMake(200,100)];
    ba.duration = 6;
    ba.autoreverses = YES;
    ba.repeatCount = HUGE_VALF;
    [emit addAnimation:ba forKey:nil];
    

    Other things to think about:

    • You can typically use nil as the key in addAnimation:forKey:, unless you’re going to need to find this animation later (e.g. to remove it or override it in some way). The key path is the important thing.

    • Setting removedOnCompletion to NO is almost always wrong and is typically the last refuge of a scoundrel (i.e. due to not understanding how animation works).

    • If, as you say, setting _emitterLayer.emitterPosition = newEmitterPosition inside the completion block does animate, then when why are you using CABasicAnimation at all? Why not just call UIView animate... and set the emitterPosition in the animations block? If that works, it will kill two birds with one stone, moving the position and animating it too.

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

Sidebar

Related Questions

I'm trying to animate a logo. The markup looks like this: <div id=logo> <h1>
I'm trying to animate a Cocos2d node and a UIKit view move like this:
I'm trying to animate drop up using negative top, the animation went okay, but
I'm trying to animate object. I use keyframe animation: I have two vertex buffers
I'm trying to animate a sequence of images and this could easily be done
I'm trying to animate a waterfall of divs like in duitang.com . i tried
I'm trying to animate a Canvas-based texture that is mapped onto a plane, like
I am trying to animate my player for walking directions (like in a birds-eye-view
I am trying to animate 2 circles like that of a beating pulse or
Hi I'm trying to animate a background image using jQuery, I tried following this

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.