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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:33:27+00:00 2026-06-04T17:33:27+00:00

I am drawing a circle in the -drawRect: method of my UIView using the

  • 0

I am drawing a circle in the -drawRect: method of my UIView using the standard CGContextFillEllipseInRect() code. However, I would like to slightly pulse (make larger and smaller) and change the intensity of the color fill with an animation. For example, if the circle is filled with red I would like to pulse the circle and make the red slightly lighter and darker in-time with the pulsing action. Not having much experience with Core Animation I am a bit lost about how to do this, so any help would be greatly appreciated.

  • 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-04T17:33:29+00:00Added an answer on June 4, 2026 at 5:33 pm

    This is much simpler if you don’t draw the circle in drawRect:. Instead, set up your view to use a CAShapeLayer, like this:

    @implementation PulseView
    
    + (Class)layerClass {
        return [CAShapeLayer class];
    }
    

    The system sends layoutSubviews to your view whenever it changes size (including when it first appears). We override layoutSubviews to set up the shape and animate it:

    - (void)layoutSubviews {
        [self setLayerProperties];
        [self attachAnimations];
    }
    

    Here’s how we set the layer’s path (which determines its shape) and the fill color for the shape:

    - (void)setLayerProperties {
        CAShapeLayer *layer = (CAShapeLayer *)self.layer;
        layer.path = [UIBezierPath bezierPathWithOvalInRect:self.bounds].CGPath;
        layer.fillColor = [UIColor colorWithHue:0 saturation:1 brightness:.8 alpha:1].CGColor;
    }
    

    We need to attach two animations to the layer – one for the path and one for the fill color:

    - (void)attachAnimations {
        [self attachPathAnimation];
        [self attachColorAnimation];
    }
    

    Here’s how we animate the layer’s path:

    - (void)attachPathAnimation {
        CABasicAnimation *animation = [self animationWithKeyPath:@"path"];
        animation.toValue = (__bridge id)[UIBezierPath bezierPathWithOvalInRect:CGRectInset(self.bounds, 4, 4)].CGPath;
        animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
        [self.layer addAnimation:animation forKey:animation.keyPath];
    }
    

    Here’s how we animate the layer’s fill color:

    - (void)attachColorAnimation {
        CABasicAnimation *animation = [self animationWithKeyPath:@"fillColor"];
        animation.fromValue = (__bridge id)[UIColor colorWithHue:0 saturation:.9 brightness:.9 alpha:1].CGColor;
        [self.layer addAnimation:animation forKey:animation.keyPath];
    }
    

    Both of the attach*Animation methods use a helper method that creates a basic animation and sets it up to repeat indefinitely with autoreverse and a one second duration:

    - (CABasicAnimation *)animationWithKeyPath:(NSString *)keyPath {
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:keyPath];
        animation.autoreverses = YES;
        animation.repeatCount = HUGE_VALF;
        animation.duration = 1;
        return animation;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Bresenham's circle algorithm for fast circle drawing. However, I also want
The source code: //The drawing of the circle on the canvas imageView = new
Hi I am drawing a circle using wxpython for a project.Please look through the
I'm not sure how to approach drawing a hollow circle in SVG. I would
How would I go about drawing a custom UIView that is literally just a
i want to crop image via drawing circle using touchMoved event. so how can
Where can I get started drawing animated geometry in C#? I would like to
I am drawing a concave shape in canvas using the following code: var ctx
I have a custom C# user-control where I would like to draw a circle
I have the following code for drawing a circle : #include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h>

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.