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

Make circle with slice cut out? iOS Swift 4

I'm trying to create a very simple colored circle inside a UIView with a slice cut out or in a different color, something like this: I expected that this would be very simple and would only require a few lines of code since CAShapeLayer allows you…
Freddy Benson
  • 735
  • 4
  • 11
  • 30
2
votes
0 answers

Drawing an animatable laser beam with CALayer

I'm trying to draw a light beam using CAShapeLayer but not able to correctly implement it. Have used the shadow properties but it isn't totally reflecting the way the beam should glow. pathLayer.path =…
2
votes
1 answer

Animating multiple UIBezier paths in a single CAShapeLayer

I want to animate drawing multiple letters on a screen. I have my data in an array. The array contains line objects, these line objects have a start and end time for the animation, and the points that make up the line. My current code is as…
Kex
  • 8,023
  • 9
  • 56
  • 129
2
votes
1 answer

CAShapeLayer get current scale

I have a CAShapeLayer that scales to an unknown scale number: myCAShapeLayer.transform = CATransform3DMakeScale(newScale, newScale, 1) Then at a certain point, I have to run a CABasicAnimation from current scale back to 1: let animation1 =…
Gizmodo
  • 3,151
  • 7
  • 45
  • 92
2
votes
0 answers

Line Animation when Editing UITextField

I'm trying to add animation to the border of UITextField when edited by the user. The idea is to show line animation in the login page once the first text field is being edited and then after the user switches to the next textfield, the line should…
Maryoomi1
  • 113
  • 1
  • 3
  • 16
2
votes
0 answers

Drawing CAShapeLayer with a big CGPath

I am creating a vector based drawing app, and being truly vector based I need to have a "limitless" canvas. So I have created the following structure: UIVIew (canvas view) | CALayer (canvas container) | CAShapeLayer (the drawn shapes) …
worriorbg
  • 351
  • 5
  • 14
2
votes
2 answers

Constructing CAShapeLayer from a multiple CGpaths

I have a CAShapeLayer that takes his shape from path. This creates a layer object which can be manipulated, like move and rotate. My problem is that I need the layer object to be composed of multiple paths. For example imagine the United States map;…
alex
  • 279
  • 4
  • 14
2
votes
1 answer

How to animate the drawing of an array of CGpath?

I am trying to make an app that draws an object for the user. I now have one of those object, which is built up of an array of type [UIBezierPath]. I then use a loop to change all the UIBezierPaths in the array into CGPaths and then want to animate…
2
votes
1 answer

Unexpected behavior in scaling CAShapeLayer

I am using the following code to scale a CAShapelayer instance (i.e., self.view.layer.sublayers![0]): class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() self.view = Map(frame: CGRect(x: 0, y: 0,…
2
votes
1 answer

CGPath curve line flickering with black filling, when fill is set to clear color

Simple sin wave CGPath. When added to layer flickering with black color, video: https://gfycat.com/PaleIllAustraliansilkyterrier Photo(it appears like this for milliseconds): shapeLayer.lineWidth = 1 shapeLayer.fillColor =…
2
votes
0 answers

UIBezierPath bezierPathWithRoundedRect wrong rounding

I'm trying to round the chat bubbles by applying bezierPathWithRoundedRect to them. Everything works almost perfect. But for some strange reason in some cases one of the corners seems to me much bigger than others. Why it happens and hou to avoid…
2
votes
1 answer

Shape in iOS app

I am making zigzag shape on UIView when I am increasing view size its not coming properly. I am using this code func zigZagShape() { let width = self.frame.size.width let height = self.frame.size.height let givenFrame =…
pooja
  • 23
  • 4
2
votes
2 answers

CAShapeLayer tap detection in Swift 3

I have a CAShapeLayer for which I have marked the fill color as clear. When I tap on the line it does not always detect if the CAShapeLayer cgpath contains the tap point. My code is as follows: override func touchesBegan(_ touches: Set,…
Rahul
  • 300
  • 2
  • 12
2
votes
1 answer

How to set corner radius value with CAShaperLayer?

i drew a vertical line with UIBeizerPath and i need this line to have a corner radius with a value of 5. i tried to recall [pathLayer setCornerRadius: 5]; but I do not get results ... Can you help me? how can I assign a corner radius value? this is…
kAiN
  • 2,559
  • 1
  • 26
  • 54
2
votes
1 answer

iOS - View background is black after adding multiple sublayers

I am creating a ring with multiple color segments. Here's my code: CGFloat viewWidth = rect.size.width; CGFloat viewHeight = rect.size.height; CGFloat lineWidth = viewWidth * 0.15f; CGFloat radius = viewWidth/2 - lineWidth; CGPoint center =…
JLT
  • 3,052
  • 9
  • 39
  • 86