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
1
vote
0 answers

Line path becomes masked when UIImageView inserted

When inserting a UIImageView (which is masked by setting the MaskView property) the line that was drawn before also becomes masked. The lines were first drawn animated using a UIBezierPath CAShapeLayer and CABasicAnimation Is there a way to keep…
empo
  • 1,133
  • 5
  • 21
  • 41
1
vote
3 answers

How to draw a circle using CAShapeLayer to be centered in a custom UIView in swift programmatically

I am trying to draw a circular progress bar using CAShapeLayer inside a custom UIView which has been auto constraint, I don't want to draw my circle in the center of my super view but rather in the center of my custom view because I have other views…
chevi99
  • 123
  • 1
  • 2
  • 17
1
vote
1 answer

1 px bordered UIBezierPath(roundedRect:byRoundingCorners:)

How to get a clean 1 px border for a UIBezierPath with different rounded corners? In the below example, I have use 3 corners. Code is inside a UIView: let borderLayer = CAShapeLayer() borderLayer.frame = bounds borderLayer.path =…
Cœur
  • 37,241
  • 25
  • 195
  • 267
1
vote
0 answers

iOS: Find bottom y coordinate of rotated and rounded view

I have a UIView with CALayer inside. And I try to add UILabel directly at the bottom of this layer. But I can't find it's coordinates. On the screenshot view got a blue color, layer - white, label - red. The 1st screenshot is how it works and the…
Artem Z.
  • 1,243
  • 2
  • 14
  • 36
1
vote
1 answer

How to animate drawing shape fit in 60 second?

I'm new to Swift and I don't have too much information about it.I would like to create animated clock with filling 'CAShapeLayer' path in time interval than tried to make it with 'CABasicAnimation' in 60 seconds. The shape fills in 49 sec and…
Coder ACJHP
  • 1,940
  • 1
  • 20
  • 34
1
vote
1 answer

Change Color of an Animated UIBezierPath at a Certain Point

I am trying to create a circular progress bar in Swift 4 using a CAShapeLayer and animated UIBezierPath. This works fine but I would like the circle to change it's strokeColor once the animation reaches a certain value. For example: Once the circle…
Jens
  • 20,533
  • 11
  • 60
  • 86
1
vote
1 answer

How can i draw smooth freehand drawing using shapelayer and bezierpath over an image

let path = UIBezierPath() shapeLayer.strokeColor = UIColor.blue.cgColor shapeLayer.lineWidth = 3 path.move(to: startPoint) path.addLine(to: point) shapeLayer.lineJoin = kCALineJoinRound shapeLayer.path =…
Faheem Rahman
  • 343
  • 2
  • 10
1
vote
1 answer

How to draw a curved line using CAShapeLayer and BezierPath in Swift 4?

I was wondering how I could render a curved line like the one shown in the picture below given two points (Point A and Point B) using CAShapeLayer and BezierPath in Swift 4? func drawCurvedLine(start: CGPoint, end: CGPoint) { //insert code…
Vince Gonzales
  • 855
  • 3
  • 20
  • 39
1
vote
1 answer

Trying to add dashed border separator in tableview

Using this example I am trying to add a dashed border to my UITableView. Trying to draw dashed border for UITableViewCell But it does not work. It shows nothing. func addDashedBottomBorder(to cell: UITableViewCell) { let color =…
Jhony
  • 187
  • 1
  • 4
  • 16
1
vote
1 answer

With strokeColor, a line is drawn from the center to the circumference

I am using swift 4. I wrote the code below and tried to draw a circle with stroke. However, with the code below I could not draw my desired circle. The problem is that the line is drawn from the center of the circle to the outer periphery (strictly…
WaFuNuke
  • 37
  • 1
  • 10
1
vote
1 answer

adding a CAShapeLayer to UIButton with AutoLaout is not show Correctly

I want to make a button with top left and botton left corner radius = 15 so i make this class to achive it class pathBUtton:UIBUtton{ override func layoutSubviews() { super.layoutSubviews() let shapeLayer =…
Yoel Jimenez del valle
  • 1,270
  • 1
  • 9
  • 20
1
vote
3 answers

CAShapeLayer hitTest touch

I can't understand why a CAShapeLayer does not respond to hitTest This function always goes to // touches is outside How do I detect a touch on a CAShapeLayer? -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { currentPoint =…
alex
  • 279
  • 4
  • 14
1
vote
1 answer

CAShapeLayer not visible in XIB swift iOS

I'm building a custom view using an XIB file. However, I am facing a problem where the layers I add to the view (trackLayer) are not shown on the xib (circleLayer is an animation and I don't expect it to render in xib which is not possible to my…
jms
  • 747
  • 6
  • 19
1
vote
1 answer

CAShapeLayer filling with another CAShapeLayer as a mask

My question is about filling animation one CAShapeLayer with another CAShapeLayer. So, I wrote some code that almost achieves my goal. I created a based layer and fill it with another. Code below: - (void)viewDidLoad { [super viewDidLoad]; …
O.Daniel
  • 123
  • 12
1
vote
1 answer

How to obtain CGPathRef from a view whose mask has been set to that CGPathRef?

I have a view whose mask I had set earlier in some method, now I want to extract the CGPathRef which was the shape of the mask without having nothing at all, just the view with mask. How do I do that? CAShapeLayer* maskLayer = [CAShapeLayer layer]; …