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
10
votes
5 answers

How to add label or text in to CAShapeLayer

Here is my class and it'll draw a circle, it looks like this: class OvalLayer: CAShapeLayer { let animationDuration: CFTimeInterval = 0.3 override init() { super.init() fillColor = Colors.green.CGColor path =…
roledene JKS
  • 405
  • 2
  • 8
  • 12
9
votes
3 answers

How to apply multiple masks to UIView

I have a question about how to apply multiple masks to a UIView that already has a mask. The situation: I have a view with an active mask that creates a hole in its top left corner, this is a template UIView that is reused everywhere in the project.…
Thomas
  • 2,003
  • 18
  • 30
9
votes
1 answer

Animate CAShapeLayer with circle UIBezierPath and CABasicAnimation

I'd like to animate a circle from angle 0 to 360 degrees in 15 sec. The animation is weird. I know this is probably a start/end angle issue, I already faced that kind of problem with circle animations, but I don't know how to solve this one. var…
Marie Dm
  • 2,637
  • 3
  • 24
  • 43
9
votes
6 answers

How to give cornerRadius for UIBezierPath

I created a rectangle using following code and now I need to rounded the corners of this rectangle. but I can't find a property called layer.cornerRadius, can anyone help me ? class OvalLayer: CAShapeLayer { let animationDuration:…
roledene JKS
  • 405
  • 2
  • 8
  • 12
9
votes
4 answers

Detecting a tap on a CAShapeLayer in Swift?

I'm quite new to iOS Development (so please forgive my ineptitude - I've looked everywhere!), and was looking to find a way to detect a tap on a CAShapeLayer. So far, I've come across hitTest. Is hitTest the best method, and if so how is it used in…
John
  • 139
  • 1
  • 1
  • 11
9
votes
4 answers

Create a UIView with only one diagonal side

I need to create a UIView that has the left border inclined with 45 degrees I was wondering,is there a way to acheive this programmatically? Does CATransform3D help me in this case since it’s not really a “3D rotation”? Edit Here's an image…
Odin
  • 642
  • 1
  • 9
  • 27
8
votes
2 answers

Swift - How to get Rounded Cap on CAShapeLayer or UIBezierPath(ovalInRect: ovalRect)

I have these 2 functions bellow in my class which extends CAShapeLayer, but I can't get an arc with rounded end caps every time I draw the path. It looks always like this picture: I already tried using kCALineCapRound with no success. Any…
8
votes
2 answers

How to draw line on Image Pattern exactly

I have a UIImageView. Inside that I am drawing a line wit user touch event. Problem is that a line can be drawn anywhere in UIImageview, but I like to draw line with image pattern only. For example, look at this image. I need to draw line on image…
8
votes
0 answers

How to merge multiple CAShapeLayers into one in swift

I've got multiple bezier paths which are incorporated into CAShapeLayers for animation purposes. I need to know if it is possible to merge all of the layers into one collection object so that I can scale it in the following way: shapes.transform =…
Matt Spoon
  • 2,760
  • 5
  • 25
  • 41
8
votes
3 answers

How to draw round dot stroke pattern for a CAShapeLayer?

I am trying to stroke the paths in CAShapeLayer using dash patterns. I have created many dash patterns using lineDashPattern property. But this property doesn't give any option for type of dash stroked. I want to be my dashes to be round dots like…
blancos
  • 1,576
  • 2
  • 16
  • 38
8
votes
2 answers

Drawing a line with Bezierpath using CAShapeLayer object

I am making an image editor which can create different shapes objects like circle, triangle and square which can also be updated or removed. So I have used CAShapeLayer for creating shapes objects. Now I also want to draw a line on image which can…
Usman Awan
  • 1,208
  • 2
  • 13
  • 30
8
votes
1 answer

Applying a CAShapeLayer mask to a UIView

I am using this code to apply a layer to a UIview: mask = [[CAShapeLayer alloc] init]; mask.frame = baseView.layer.bounds; CGRect biggerRect = CGRectMake(mask.frame.origin.x, mask.frame.origin.y, mask.frame.size.width,…
Alessandro
  • 4,000
  • 12
  • 63
  • 131
7
votes
2 answers

UIBezierPath - Add rounded corner

I am using a UIBezierPath to draw a curved line. The curve works however, I am unable to curve the edges of the line. If you look at the top/bottom end of the curve, you can see that the edges are flattened out, thats not what I want. Is there a…
Supertecnoboff
  • 6,406
  • 11
  • 57
  • 98
7
votes
1 answer

Strange behaviour when animating between two circular UIBezierPaths

The Problem I am creating an exploding rings effect. I'm using multiple CAShapeLayer's and creating a UIBezierPath for each layer. When the view is initialised, all the layers have a path with width 0. When an action is triggered, the rings animate…
Ollie
  • 1,926
  • 1
  • 20
  • 35
7
votes
4 answers

Centre Align CAShape layer in a UIView

The following is a image for which the the code does not align the centre of the UIView , white color. CAShapeLayer *layer = [CAShapeLayer layer]; layer.anchorPoint=CGPointMake(0.5, 0.5); layer.path=[UIBezierPath…
NNikN
  • 3,720
  • 6
  • 44
  • 86
1 2
3
63 64