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
5
votes
1 answer

Sine CAShapeLayer as a mask of CALayer

I'm trying to implement the next curious thing: I have a few dots and I'd like to link them with sine waves Next method returns the array of dots for making plot: - (NSArray *)plotPointsBetweenPoint:(CGPoint)pointA andPoint:(CGPoint)pointB { …
agoncharov
  • 822
  • 1
  • 6
  • 15
5
votes
1 answer

touchesMoved drawing in CAShapeLayer slow/laggy

As was suggested to me in a prior StackOverflow question, I'm trying to improve my drawing method for letting my user draw lines/dots into a UIView. I'm now trying to draw using a CAShapeLayer instead of dispatch_async. This all works correctly,…
klcjr89
  • 5,862
  • 10
  • 58
  • 91
5
votes
3 answers

Get position of path at time

is there a nice way to calculate the position of a path (CGPath or UIBezierPath) at a given time (from 0 to 1)? Using CAShapeLayer for example, one can create an animated stroke end. I want to know the position of that stroke end at arbitrary…
5
votes
2 answers

iOS create the inverse of a CAShapeLayer mask

So I am a fresh iOS developer working on an iOS drawing application that plays back user sketches using x/y coordinates and timestamps. To draw simple pen events i have a UIView that serves as the drawing view and I draw to the view using…
Maksim
  • 16,635
  • 27
  • 94
  • 135
5
votes
2 answers

CAShapeLayer not updating when changing path

I'm using a CAShapeLayer. I'm trying to make it so that its path changes whenever a mouse event occurs. For example, when a mouse down event occurs, a path is appended to a CGMutableRefPath and then then the shape layer's path is set to it. The…
user2647249
  • 149
  • 1
  • 6
5
votes
0 answers

Create a CALayer mask by combining multiple paths

I'm trying to create a mask for a CALayer containing an image. This mask shall be able to use the union of multiple paths or the inverse of the union. In terms of a venn diagram that would be a disjunction or a joint denial (look here for graphics…
user511
  • 154
  • 1
  • 7
5
votes
1 answer

Best way to draw circle on top of UIImageView IOS

I have a UIImageView that shows a picture the user has just taken with the camera. On that image i need to draw a transparent movable circle thats a set size. So when the user drags their finger over the image the circle moves with it. Then if the…
MrBeanzy
  • 2,286
  • 3
  • 28
  • 38
5
votes
1 answer

CGContext vs CALayer

I'm trying to get a handle on Quartz 2D and looking at the online book Quartz 2D Graphics for Mac OS X Developers. One very basic thing that is confusing me is the CGContext. For example, I can draw a simple "U" shape with the code below and use it…
spring
  • 18,009
  • 15
  • 80
  • 160
5
votes
2 answers

Crash using [UIBezierPath CGPath] with CAShapeLayer under ARC

I'm getting a BAD ACCESS error using [UIBezierPath CGPath] with CAShapeLayer under ARC. I've tried bridging in various ways but I'm not clear if that is the problem. I have isolated the crash to using the result of the makeToPath method: maskLayer…
spring
  • 18,009
  • 15
  • 80
  • 160
5
votes
2 answers

How to redraw a CAShapeLayer when modifying his path?

I'm trying to add a subpath to my CAShapeLayer's path, but the changes doesn't show unless I first assing nil to the path and then I reassign myPath to the CAShapeLayer. I've tried with setNeedsRedisplay but it doesn't works. This is the code in the…
Pablo3D
  • 71
  • 1
  • 5
5
votes
2 answers

(iOS) How to animate rounded rectangle with shapeLayer?

I am trying to animate the width of a rounded rectangle, the problem is when going from bigger width to thinner width, the animation does an "aberration ease jump". Here's the code: shapeLayer = [CAShapeLayer layer]; shapeRect = CGRectMake(0.0f,…
murb83
  • 325
  • 3
  • 14
4
votes
2 answers

Animating CAShapeLayer with moving frame

Using core animation layers, I've been trying to implement the following feature. Within a containing superlayer, there are two anchor layers, and another layer that connects the two. The following image should make the situation clear. On the…
4
votes
1 answer

Help - Scaling CAShapeLayer (i.e. path) in UIScrollView

I have a problem and I hope you can help me with it. This is for iPad by the way. I have a UIScrollView, UIImageView, CAShapeLayer, and a CGMutablePathRef. 1- So, I loaded an Image in the UIImageView 2- Then, I parsed all the paths from a file, then…
NewUser_
  • 331
  • 1
  • 2
  • 9
4
votes
1 answer

Animating a CAShapeLayer along an oval UIBezierPath

I am trying to animate a CAShapeLayer along a UIBezierPath. This works fine in circular path situations, but not when I use an oval path. The animation does happen, but pauses for a short period every time it has made a round, without me setting a…
Harold
  • 205
  • 2
  • 11
4
votes
1 answer

Animate CAShapeLayer path with CASpringAnimation

I have a custom UIView where I add a CAShapeLayer as a direct sublayer of the view's layer: private let arcShapeLayer = CAShapeLayer() The CAShapeLayer has the following properties (the border is to visualize more easily the animation) declared in…
TheoK
  • 3,601
  • 5
  • 27
  • 37