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
4
votes
2 answers

CAShapeLayer Slow User Interaction

I have a CAShapeLayer and it has to do a simple task of moving on the screen, guided by the user's finger. The problem is that the movement is too slow. The layer does move, but there is a lag and it feels slow. I have another test app where an…
alex
  • 279
  • 4
  • 14
4
votes
1 answer

containsPoint doesn't work with CAShapeLayer?

I have two CAShapeLayers insde the main layer of UIView. The CAShapeLayers have complex shapes and I need to know if a point was touched within the shape boundaries. Also, I need to know which shape got touched. I am trying the containsPoint, but…
alex
  • 279
  • 4
  • 14
4
votes
1 answer

Animate CAShapeLayer path from old value to new value in Swift

I'm new to Core Animation, and I'm trying to update the strokeEnd of a CAShapeLayer, from an old value to a new updated value, based on new data. So basically I have a drawn CAShapeLayer, and updating it's UIBezierPath, and using…
T. Hyldgaard
  • 328
  • 8
  • 16
4
votes
3 answers

How to draw a just the corners of a rectangle (without lines connecting them)

I have a CGRect value and need to draw a border around it. I just want the corners to be drawn without any lines connecting them. Something like this... How would I draw this figure using swift?
coder
  • 381
  • 2
  • 22
4
votes
2 answers

How to cut edges of a uiview in swift

I attached the View image. I want to achieve the small cut in bottom between the buy button and above flight information view.
Yasheed Mohammed
  • 187
  • 1
  • 14
4
votes
1 answer

macOS High Sierra and CAShapeLayers, NSImageView, NSTableView confilcts

I have updated to macOS High Sierra and have now unexpected problems in my project, the problems not seen before in macOS Sierra. I have custom NSImageView and after drag and drop of image in this NSImageView I can draw the rectangles on top of the…
VYT
  • 1,071
  • 19
  • 35
4
votes
1 answer

Swift UIView: make a path always be at the end of person's finger?

OK, I am new to UIBezierPaths but I need to have a path whose endpoint updates according to where the user's finger is. It should change in touchesMoved So far I have: func customInit() { print("init scene") self.backgroundColor =…
blue
  • 7,175
  • 16
  • 81
  • 179
4
votes
2 answers

Why using dispatch_async is so slow compared to not using it at all?

I wanted to know why my code runs much slower when I use dispatch_async compared to when I don't use it at all. I'm trying to blur the edges of my UIImage by masking it and using UIGraphicsImageRenderer (Not sure if it's the most efficient way or…
Reza.Ab
  • 1,195
  • 1
  • 11
  • 21
4
votes
3 answers

CAShapeLayer missing pixel in top-left corner

I'm using a CAShapeLayer with a UIBezierPath to draw a bordered box in a view. This is working fine, but the very first pixel (top, left) is not drawn. This is my code: let focusSize = CGRect(x: focusX, y: focusY, width: focusWidth, height:…
Rob
  • 4,927
  • 12
  • 49
  • 54
4
votes
1 answer

Centering a CAShapeLayer within a UIView?

There are probably more than 5 questions just like this one, but none of them solve the problem. I want to center a circle on a view. It's not happening despite trying all kinds of methods through similar questions like this one. I'm not sure if…
rocky raccoon
  • 514
  • 1
  • 8
  • 23
4
votes
1 answer

Shape a triangle with UIView backed by CAShapeLayer

From the tutorial : http://swiftiostutorials.com/tutorial-draw-nice-triangle-view-border-cashapelayer/, i managed to create a triangle like : class Triangle: UIView { override func drawRect(rect: CGRect) { let mask = CAShapeLayer() …
Orange
  • 59
  • 2
  • 14
4
votes
1 answer

CAShapeLayer shadowPath animation. How to prevent shadow fill on animation completion?

I'm creating a random UIBezierPath, setting the path to a CAShapeLayer's .path property, and then animating the CAShapeLayer's stroke like so: // Get a path let path = createBezierPath() // Shape layer properties let color =…
Daniel Storm
  • 18,301
  • 9
  • 84
  • 152
4
votes
1 answer

How to rounded the corners when I draw rectangle using UIBezierPath points

I crated a rectangle using UIBezierPath adding point by point, now I want to rounded the corners of this rectangle but seems there are no way to do it. can anyone help me ? class RectangleLayer: CAShapeLayer { let animationDuration:…
roledene JKS
  • 405
  • 2
  • 8
  • 12
4
votes
1 answer

how to 'animate' changing shape of a view in IOS? (i.e. change it's path from one to another)

How can one 'animate' changing a custom UIView based around a shape, from one shape to another shape? Say for example one is creating a UIView that appears like a shape, created using a UIBezierPath. But then you want this view object to change…
Greg
  • 34,042
  • 79
  • 253
  • 454
4
votes
3 answers

How to add background line in multiline label using NSAttributedString in ios objective-c

I want to add background line in multiline label using NSAttributedString in objective-c as shown in image below I used following code [yourView.layer setBorderWidth:5.0]; [yourView.layer setBorderColor:[[UIColor colorWithPatternImage:[UIImage…
Nischal Hada
  • 3,230
  • 3
  • 27
  • 57