Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><img src="https://i.stack.imgur.com/4zqWd.png" alt="Dot Image"></p> <p>The key to the approach used to draw the image shown above is using <code>CGContextDrawRadialGradient</code> to draw the dot. We can then use this dot image as the contents of a <a href="https://developer.apple.com/library/ios/#documentation/graphicsimaging/reference/CALayer_class/Introduction/Introduction.html" rel="nofollow noreferrer">CALayer</a>, allowing us to reposition it and animate it as we see fit. </p> <p>In your original question you asked...</p> <blockquote> <p>how to make that center point with <strong>animation effect</strong> shown in Image?</p> </blockquote> <p>...but as a still image it doesn't show any animation. I've made an educated guess as to how you envisioned the dot be animated.</p> <p>The following code creates a gradated dot with a pulsating animation, fading in and out repeatedly:</p> <h2>Code</h2> <pre><code>#import &lt;QuartzCore/QuartzCore.h&gt; ... - (void)viewDidLoad { [super viewDidLoad]; CGFloat dotDiameter = 30.f; CGFloat dotRadius = dotDiameter * 0.5; CGRect dotRect = CGRectMake(CGRectGetMidX(self.view.frame) - dotRadius, CGRectGetMidY(self.view.frame) - dotRadius, dotDiameter, dotDiameter); CALayer *dotLayer = [CALayer layer]; dotLayer.contents = (id)[self dotImageOfDiameter:dotDiameter].CGImage; dotLayer.cornerRadius = dotRadius; dotLayer.frame = dotRect; dotLayer.masksToBounds = YES; // Animate the dot to make it appear to pulsate. CABasicAnimation *pulseAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"]; pulseAnimation.autoreverses = YES; pulseAnimation.duration = 0.8; pulseAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; pulseAnimation.repeatCount = INFINITY; pulseAnimation.toValue = [NSNumber numberWithFloat:1.0f]; [dotLayer addAnimation:pulseAnimation forKey:@"opacity"]; [self.view.layer addSublayer:dotLayer]; } - (UIImage *)dotImageOfDiameter:(CGFloat)diameter { UIGraphicsBeginImageContextWithOptions(CGSizeMake(diameter, diameter), NO, 0.0f); CGContextRef context = UIGraphicsGetCurrentContext(); CGFloat radius = diameter * 0.5; CGColorSpaceRef baseColorSpace = CGColorSpaceCreateDeviceRGB(); CGFloat colours[8] = { 0.56f, 0.78f, 0.94f, 1.0f, // Opaque dot colour. 0.56f, 0.78f, 0.94f, 0.0f }; // Transparent dot colour. CGGradientRef gradient = CGGradientCreateWithColorComponents (baseColorSpace, colours, NULL, 2); CGContextDrawRadialGradient(context, gradient, CGPointMake(radius, radius), 0.0f, CGPointMake(radius, radius), radius, kCGGradientDrawsAfterEndLocation); CGImageRef dotImageRef = CGBitmapContextCreateImage(context); UIImage *dotImage = [UIImage imageWithCGImage:dotImageRef]; CGColorSpaceRelease(baseColorSpace); CGGradientRelease(gradient); CGImageRelease(dotImageRef); UIGraphicsEndImageContext(); return dotImage; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload