Questions tagged [cashapelayer]

CAShapeLayer is a special purpose CALayer subclass for drawing animatable shapes using cubic Bezier splines. It's a part of the QuartzCore framework and is available for both iOS (since iOS 3.0) and OS X (since OS X v10.6 "Snow Leopard").

CAShapeLayer is a special purpose CALayer subclass for drawing animatable shapes using cubic Bezier splines. It's a part of the framework and is available for both (since iOS 3.0) and (since OS X v10.6 "Snow Leopard").

The shapes is defined using the path property and can be both filled and stroked using the fillColor and strokeColor properties. Note that the backgroundColor property inherited from CALayer does not fill the shape. The path of the shape is animatable (but doesn't support implicit animations) but the appearance of the animation is undefined if the two paths have a different number of control points or segments.

There are several properties (animatable) to configure how the shape is stroked and filled. Using these properties the stroke can for example get a moving dashed patten (commonly called "marching ants").

The strokeStart and strokeEnd properties can also be used to only stroke part of the shape or to animate the shape being stroked. Both values go from 0.0 (beginning of path) to 1.0 (end of path) and values in between are interpolated along the path.


The page about Paths in the Quartz 2D Programming Guide is a great resource for learning more about creating paths, stroking, rounding and joining paths, filling paths and creating dash patterns.

951 questions
2
votes
1 answer

How to change area inside CAShapeLayer?

I have created CAShapeLayer with custom UIBezierPath and filled color. How can I change the area inside a path? Make it bigger/lower. private var path = UIBezierPath() private var shapeLayer = CAShapeLayer() override public func…
user2398911
  • 96
  • 1
  • 14
2
votes
1 answer

Animating a circles progress more than once with CAShapeLayer

I need to animate a circle's progress when the user taps a button. I am currently using a CAShapeLayer and CABasicAnimation. Code like so: import UIKit class ViewController: UIViewController { @IBOutlet weak var circleContainerView: UIView! …
Kex
  • 8,023
  • 9
  • 56
  • 129
2
votes
1 answer

CAShapeLayer() draws weird line/path

I have a CAShapeLayer() with a gradient on top which is being animated, but somehow it looks like in the image below: How come it looks like this? My code: override func viewDidLayoutSubviews() { displayLine() } override func viewDidAppear(_…
Tom
  • 3,672
  • 6
  • 20
  • 52
2
votes
1 answer

Adding a sub layer or UIView as subview to the top using z-order of UIButton still goes behind the view or look transparent

I have a UIButton and i want to add a circle badge on top of it, here is how it looks. public func addCircleBadge(_ width: CGFloat, color: UIColor) { let bounds = self.mybtn.bounds let layer = CAShapeLayer() let radius =…
Fahadsk
  • 1,099
  • 10
  • 24
2
votes
0 answers

Add gradient color on every ca shapelayer

I am trying to add gradient on ca shape layer its only giving gradient effect on current view frame if i am using it by adding masklayer it is not effecting on every layer seperately here is my code: CAShapeLayer *gradientMask = [CAShapeLayer…
2
votes
1 answer

Simple confetti effect using CAShapeLayer and CoreAnimation on iphone?

I am building a fairly simple game on my app. the app UI is based a lot core animation so does the game. I am trying to achieve a simple confetti effect for the game using CAShapeLayer and core animation (in the style of the confetti in "cut the…
shannoga
  • 19,649
  • 20
  • 104
  • 169
2
votes
2 answers

Programmatically created UIView's frame is 0

Cannot access uiview's frame after setting it's layout. Frame, and center is given as 0,0 points. I should also mention that there are no storyboard's in this project. All views and everything are created programmatically. I have created a UIView…
emrepun
  • 2,496
  • 2
  • 15
  • 33
2
votes
2 answers

Swift - Creating a connection between two labels or button using blue drag line like in Xcode

I have managed to create the blue line like in Xcode but how would you recognise when the end point of the line is dragged and released above the other labels or buttons so a connection can be made? Code class ViewController: UIViewController…
STerrier
  • 3,755
  • 1
  • 16
  • 41
2
votes
1 answer

animate CAShapeLayer on circular path

I want to animate my thumb layer on the drawn path. I can animate the progress layer as per the value but, moving the entire layer doesn't work. func setProgress(_ value:Double, _ animated :Bool) { let progressAnimation =…
rv7284
  • 1,092
  • 9
  • 25
2
votes
1 answer

How to reset a CABasicAnimation before it has ended?

I have a CAShapelayer circle that I animate as a progress circle with CABasicAnimation from 0 back to 360 degrees alongside a countdown timer in statemachine with Reset, Play, Pause, and Complete states. Right now, I can play or pause and resume…
agastache
  • 97
  • 1
  • 8
2
votes
1 answer

How to add dashed border on View's frame not on bounds [Swift]

I am trying to add a dashed border on View which will always be on the view's frame not on it's bound . My code : func addDashedBorder() { let color = UIColor.red.cgColor shapeLayer = CAShapeLayer() let frameSize = self.bounds.size …
Dhiru
  • 3,040
  • 3
  • 25
  • 69
2
votes
2 answers

Rounded Curve Edge for UIView

I am trying to add rounded edges via this extension , however I am getting proper rounded UIView in iPhone X but when I try to run this same code in iPhone 6s , its like not getting curved , tried to increase the desiredCurve still not able to see…
2
votes
1 answer

How to centre my CAShapeLayer within UIView - Swift?

I am trying to create a loading progress circle popup with a UIViewController. I am having issues trying to get my circle within a UIView that is a subView of the parent view. Please can someone advice? I am trying to create a loading progress…
dean
  • 321
  • 3
  • 17
2
votes
2 answers

iOS morphing play/pause animation

I would like to have a YouTube like morphing play/pause animation in the app I am developing. It looks like the animation here. I am not sure how to go about it. I know I need a CABasicAnimation and CAShapeLayer. I know I need two (or maybe more?)…
surToTheW
  • 772
  • 2
  • 10
  • 34
2
votes
1 answer

How do I remove a CAShapeLayer in progressbar circle

I have the following code, which I am implementing to download a PDF with a progress circle. It is working for me, first I check that the file is already saved in the "Documents" directory and if it is true I simply show the PDF, and if the pdf file…
Mario Burga
  • 1,107
  • 1
  • 13
  • 19