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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:45:40+00:00 2026-06-04T11:45:40+00:00

I am trying to show a simple point moving. I set up a layer,

  • 0

I am trying to show a simple point moving. I set up a layer, set the bounds, position and color, and then use CAAnimation to show it moving

    CALayer *l = [CALayer layer];

    l.bounds = CGRectMake(0,0,20,20);
    l.position = CGPointMake(x,y);
    l.cornerRadius = 10;
    l.backgroundColor = [UIColor blueColor].CGColor;

    [self.theView.layer addSublayer:l];


    CABasicAnimation *anim1 = [CABasicAnimation animationWithKeyPath:@"position"];
    anim1.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    CGPoint to = CGPointMake(x+dx, y+dy);
    anim1.fromValue = [l valueForKey:@"position"];
    anim1.toValue = [NSValue valueWithCGPoint:to];
    l.position = to;
    anim1.duration = 3.0;

When I run this, I see two blue circles moving. I want to see one circle moving from (x,y) to (x+dx,y+dy). Could someone clue me in on what I’m doing wrong?

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-06-04T11:45:42+00:00Added an answer on June 4, 2026 at 11:45 am

    It only shows one circle for me but I added the animation to the layer (which your code sample doesn’t do) like this (after your last line of code):

    [l addAnimation:anim1 forKey:@"myNumberOneAnimation"];
    

    Without that line of code you get an implicit animation from setting the position of the layer. Changing animatable properties of layers that aren’t associated with a view causes implicit animations. When you on the other hand explicitly animate the position by adding the animation to the layer it will show instead of the implicit animation.

    You can also configure the animation looks before it begins and after it finishes by changing the fillMode like this:

    anim1.fillMode = kCAFillModeBoth;
    

    If adding these lines doesn’t fix the problem then it’s somewhere else in your code. If so, please post more of the code where you are animating or changing the properties of the “l” layer.

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

Sidebar

Related Questions

I'm very new to flash. I'm trying to show a simple button for my
I'm using simple jcarousel here is ther code: http://jsfiddle.net/w6fLA/ I'm trying to show div
I am trying to build a simple page that will show book information, I
I'm trying to do a simple animation. You show the div. It animates correctly.
On the click of a button, I'm trying to show a simple hidden div
I am trying to build a sample application which will show a proof of
Trying to show a label only when a certain item in a combo is
I am trying to show by example that the prefix increment is more efficient
I'm trying to show updated results for a CCK Computed Field. The computation is
I'm trying to show thumbnail images in Django admin, but I can only see

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.