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

Why does applying a bezierPathWithRoundedRect mask yield a different result from setting the layer's cornerRadius?

I typically use the cornerRadius property to apply rounded corners to view layers. When the views only need rounded top or bottom corners, I apply a mask with a bezier path instead (using bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:).…
hverlind
  • 500
  • 1
  • 7
  • 14
3
votes
3 answers

Animation CAShapeLayer

I draw a graph with this code: CAShapeLayer *curentGraph = [CAShapeLayer new]; CGMutablePathRef linePath = CGPathCreateMutable(); curentGraph.lineWidth = 3.0f; curentGraph.fillColor = [[UIColor clearColor] CGColor]; curentGraph.strokeColor =…
Max Sim
  • 81
  • 1
  • 7
3
votes
1 answer

How to rotate a CAShapeLayer at its center point

I have made a CAShapeLayer with few points by setting its stroke color to red . Then i have filled the color with a pattern of an UIImage. I want to rotate that CAShapeLayer along with its filled pattern using UIRotationGestureRecognizer. I have…
3
votes
1 answer

iOS: UIBezierPath and CAShapeLayer fillRule

I have used both UIBezierPath and CAShapeLayer before. But almost every time in conjunction with filling the object contained within the path with color inside. But I would like this time to fill the color outside of the object contained by the…
Unheilig
  • 16,196
  • 193
  • 68
  • 98
3
votes
3 answers

Why the circle path of the cashapelayer is not so round?

The doucumet said that the CAShapLayer is anti-aliased ,why got this result. I also draw a circle with the CGContext in the drawRect method,It's very perfect. UIBezierPath *path = [UIBezierPath bezierPath]; [path appendPath:[UIBezierPath…
Luke
  • 370
  • 4
  • 11
3
votes
1 answer

Getting issue in CGPath Scale

I am drawing polygon using CGPath and adding to CAShapeLayer.I want to scale my CGPath when user click on it. I know how to scale CGPath. But when i click my CGPath, my CGPath drawing far from centre while i am drawing polygon in…
h999
  • 395
  • 1
  • 5
  • 21
3
votes
2 answers

How to stroke a dashed CGPath with two alternating colours in Cocoa?

I would like to stroke the path of a CAShapeLayer with two alternating colours (black and white for example, think Preview.app selection boxes). I am not sure how to do this, or whether this is even possible with Quartz. I have set up a CAShapeLayer…
Daniel Farrell
  • 9,316
  • 8
  • 39
  • 62
3
votes
3 answers

How to draw a filled path/shape in different colors

I need to color a shape on my screen any color I wish. I am currently trying to do this with a UIImage which I want to recolor to my desires. The only way to do this, as far as I know, is to take the individual pixels of the UIImage, which calls for…
67cherries
  • 6,931
  • 7
  • 35
  • 51
3
votes
1 answer

CAShapeLayer and UIImage

I have been trying to learn more about using CAShapeLayer animating it using path. The first thing came to my mind was having the effect of a "compressed" tennis ball against the edge before it bounces off. But rather than using the fillPath of…
Unheilig
  • 16,196
  • 193
  • 68
  • 98
3
votes
1 answer

iphone-give transparent background to CAShapeLayer *maskLayer

I have a UIImageView on UIView. On that I have drawn a shape using UIBezierPath. Now I want other part to be transparent. My code is, - (void)drawRect:(CGRect)rect { self.backgroundColor = [[UIColor clearColor] colorWithAlphaComponent:0.0]; …
Durgaprasad
  • 1,910
  • 2
  • 25
  • 44
3
votes
2 answers

Optimization of drawing lines, possible alternatives to CAShapeLayer

I need to draw many lines (in the range of 50-75) in a screen and currently use the below function for it which works fine. After drawing 40-50 of these lines with the below code, the application slows down noticeably in my iPhone 4. To optimize I…
guenis
  • 2,520
  • 2
  • 25
  • 37
3
votes
1 answer

Transforming a Stroked CAShapeLayer

I have a CAShapeLayer which contains a CGMutablePath that has a stroke drawn around it. In my app, I transform this CAShapeLayer to increase / decrease it's size at certain times. I'm noticing when I transform the CAShapeLayer, the stroke gets…
Ser Pounce
  • 14,196
  • 18
  • 84
  • 169
3
votes
3 answers

CAShaperLayer -renderInContext Doesn't Work?

I am able to create a UIImage from a Core Animation layer using the following code: - (UIImage*)contentsImage; { UIGraphicsBeginImageContext([self bounds].size); [self renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image =…
Matt Long
  • 24,438
  • 4
  • 73
  • 99
3
votes
1 answer

Animating CAShapeLayer's strokeColor with CABasicAnimation

I've been unsuccessful at animating a flashing stroke on a CAShapeLayer using the answer from this previous thread, and after many searches I can find no other examples of animating the stroke using CABasicAnimation. What I want to do is have the…
Michael Mangold
  • 1,741
  • 3
  • 18
  • 32
3
votes
2 answers

UIGraphicsGetImageFromCurrentImageContext with CALayers

I am trying to create an image of a UIView with CALayer sublayers. With this code - (UIImage*)snapshot{ UIGraphicsBeginImageContext(self.bounds.size); [self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *viewImage =…
jadengeller
  • 1,307
  • 1
  • 14
  • 26