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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:41:21+00:00 2026-05-18T10:41:21+00:00

I have two circles which move around the screen. The circles are both UIViews

  • 0

I have two circles which move around the screen. The circles are both UIViews which contain other UIViews. The area outside each circle is transparent.

I have written a function to create a CGPath which connects the two circles with a quadrilateral shape. I fill this path in a transparent CALayer which spans the entire screen. Since the layer is behind the two circular UIViews, it appears to connect them.

Finally, the two UIViews are animated using Core Animation. The position and size of both circles change during this animation.

So far the only method that I have had any success with is to interrupt the animation at regular intervals using an NSTimer, then recompute and draw the beam based on the location of the circle’s presentationLayer. However, the quadrilateral lags behind the circles when the animation speeds up.

Is there a better way to accomplish this using Core Animation? Or should I avoid Core Animation and implement my own animation using an NSTimer?

  • 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-18T10:41:22+00:00Added an answer on May 18, 2026 at 10:41 am

    I faced a similar problem. I used layers instead of views for the animation. You could try something like this.

    1. Draw each element as a CALayer and include them as sublayers for your container UIVIew’s layer. UIViews are easier to animate, but you will have less control. Notice that for any view you can get it’s layer with [view layer];
    2. Create a custom sublayer for your quadrilateral. This layer should have a property or several of properties you want to animate for this layer. Let’s call this property “customprop”. Because it is a custom layer, you want to redraw on each frame of the animation. For the properties you plan to animate, your custom layer class should return YES needsDisplayForKey:. That way you ensure -(void)drawInContext:(CGContextRef)theContext gets called on every frame.
    3. Put all animations (both circles and the quad) in the same transaction;

    For the circles you can probably use CALayers and set the content, if it is an image, the standard way:

    layer.contents = [UIImage imageNamed:@"circle_image.png"].CGImage;
    

    Now, for the quad layer, subclass CALayer and implement this way:

    - (void)drawInContext:(CGContextRef)theContext{
      //Custom draw code here
    }   
    + (BOOL)needsDisplayForKey:(NSString *)key{
       if ([key isEqualToString:@"customprop"])
          return YES;
        return [super needsDisplayForKey:key];
    }   
    

    The transaction would look like:

    [CATransaction begin];
    CABasicAnimation *theAnimation=[CABasicAnimation animationWithKeyPath:@"customprop"];
    
    theAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(1000, 1000)];
    theAnimation.duration=1.0;
    theAnimation.repeatCount=4;
    theAnimation.autoreverses=YES;
    theAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
    theAnimation.delegate = self;
    [lay addAnimation:theAnimation forKey:@"selecting"];
    
    [CATransaction setValue:[NSNumber numberWithFloat:10.0f]
                         forKey:kCATransactionAnimationDuration];
    circ1.position=CGPointMake(1000, 1000);
    circ2.position=CGPointMake(1000, 1000);
    [CATransaction commit];
    

    Now all the draw routines will happen at the same time. Make sure your drawInContext: implementation is fast. Otherwise the animation will lag.

    After adding each sublayer to the UIViews’s layer, rememeber to call [layer setNeedsDisplay]. It does not get called automatically.

    I know this is a bit complicated. However, the resulting animations are better than using a NSTimer and redrawing on each call.

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

Sidebar

Related Questions

I have two applications written in Java that communicate with each other using XML
In my application I have two images which are arranged in circle. I want
I have two 2d circles in 3d space (defined by a center, normal, and
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
Is there a built-in function to detect collision between two circles? I have used
I have a circle which is actually a latlon position with a radius measured
I have an interface named SHAPE . CIRCLE and RECTANGLE are two classes implementing
I have two resources in my XAML which represent a Star and a Half
I have a list of two-dimensional points and I want to obtain which of
I have an applet which displays some data using circles and lines. As the

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.