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

Swift how to mask shape layer to blur layer

I was making a progress circle, and I want its track path to have a blur effect, is there any way to achieve that? This is what the original track looks like(the track path is transparent, I want it to be blurred) And this is my attempt let…
Zim
  • 674
  • 7
  • 15
2
votes
2 answers

Remove tab bar background when using custom layer

I have created a custom rounded floating tab bar successfully but how can i removed the default tabbar (shown with arrow in the picture). I tried to set tabbar background to UIImage() and set background color to clear but it is still not…
IskandarH
  • 99
  • 1
  • 13
2
votes
1 answer

Using Swift and CAShapeLayer() with masking, how can I avoid inverting the mask when masked regions intersect?

This question was challenging to word, but explaining the situation further should help. Using the code below, I'm essentially masking a circle on the screen wherever I tap to reveal what's underneath the black UIView. When I tap, I record the…
Justin
  • 319
  • 3
  • 13
2
votes
3 answers

Animate a UIBezierPath hexagon like UIActivityIndicatorview

I'm trying to achieve exactly the same animation shown below . and my output using UIBezierPath and CABasicAnimation is this below. Here is my LoaderView code class LoaderView: UIView { private let lineWidth : CGFloat = 5 internal var…
govind kumar
  • 205
  • 4
  • 12
2
votes
0 answers

Removing sublayers from a UIView layer causes app to crash

I have a simple view that uses UITouch events to draw a UIBezierPath. It all works fine until I try to clear the view. Specifically, it works twice, and on the third attempt to draw a line, the app crashes. For an extra bit of complexity, the…
gargantuan
  • 8,888
  • 16
  • 67
  • 108
2
votes
0 answers

Merge CAShapeLayer into CVPixelBuffer

I'm capturing the output of a playing video using AVPlayerItemVideoOutput.copyPixelBuffer I'm able to convert the pixel buffer into a CIImage, then render it back into a pixel buffer again, and then an AVAssetWriter writes the buffer stream out to a…
Steve Macdonald
  • 1,745
  • 2
  • 20
  • 34
2
votes
0 answers

Why can't I animate the path of a layer's sublayer as part of a CAAnimationGroup, but I can animate other properties in the group?

Thanks to @matt, I learned a while back that it is possible to animate multiple layers' properties in a CAAnimationGroup. The trick is to add name the child layer(s). See Matt's answer in this thread for a discussion of the technique, plus a working…
Duncan C
  • 128,072
  • 22
  • 173
  • 272
2
votes
2 answers

How do I make everything outside of a CAShapeLayer black with an opacity of 50% with Swift?

I have the following code which draws a shape: let screenSize: CGRect = UIScreen.main.bounds let cardLayer = CAShapeLayer() let cardWidth = 350.0 let cardHeight = 225.0 let cardXlocation = (Double(screenSize.width) - cardWidth) / 2 let cardYlocation…
Ethan Allen
  • 14,425
  • 24
  • 101
  • 194
2
votes
2 answers

swift CAShapeLayer strokeColor by gradient color

hi i have a circle shapeLayer need color by GradientColor i tried ues CAGradientLayer and mask it like this let gradientChargeLayer = CAGradientLayer() gradientChargeLayer.colors = CGColor.mColor gradientChargeLayer.frame = vShape.bounds …
saint
  • 103
  • 11
2
votes
1 answer

How to draw a custom shape in the UIView for a table view header section?

I am trying to draw a custom shape in the headerView for a given section in my UITableviewController. Here is my code: func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 10 } func tableView(_…
bitops
  • 4,022
  • 3
  • 26
  • 31
2
votes
2 answers

CABasicAnimation CALayer Path Animation Direction

I am trying to animate layer path property using CABasicAnimation key path But. not getting exact results What change of path animation i am looking for is below Expected Animation Note:- Please ignore switch.. my focus is just path change from…
Jawad Ali
  • 13,556
  • 3
  • 32
  • 49
2
votes
1 answer

Animate sublayers of a layer

I'm having a view that draws 2 layers; A line A gradient Now when I switch my path I want to animate both layers at the same time. So to do that I first had 2 separate layers and added an animation to each one of them. That worked, but I didn't…
user2023106
2
votes
2 answers

Glitch at start of CABasicAnimation

I have a scaling/pulsing animation that is working on cgPaths in a for loop as below. This code works but only when you append the animatedLayers to the circleLayer path when the circleLayer has already been added to the subLayer and this creates a…
axelmukwena
  • 779
  • 7
  • 24
2
votes
1 answer

Drawing pixelated lines

I am attempting to draw "pixelated" or "vectorized" lines that look like this style: Ideally I am trying to draw a path via something like CAShapeLayer and have the path be pixelated to this style. It doesn't need to look super great like an…
harrisondev
  • 127
  • 7
2
votes
3 answers

Animating line shaped CAShapeLayer in circular path

I'm trying to animate my line shaped CAShapeLayer along a circular path. I created a initial path of my line layer and final path and added them to from and to values of CABasicAnimation. However animation is not what I was expecting. Im stuck here…
Jaffer Sheriff
  • 1,444
  • 13
  • 33