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

Animating CAShapeLayer according to button (using auto layout)

My button is being resized by using auto layout. The button has a CAShapeLayer which it's frame is being set at layoutSubviews: var initial = true override func layoutSubviews() { super.layoutSubviews() if initial { border.frame =…
Henny Lee
  • 2,970
  • 3
  • 20
  • 37
2
votes
2 answers

How to create an animation that rotate CAShapeLayer in swift

This is my code : import UIKit class circularLoaderView: UIView { let circlePathLayer = CAShapeLayer() let circleRadius: CGFloat = 20.0 override init(frame: CGRect) { super.init(frame: frame) configure() } …
dramasea
  • 3,370
  • 16
  • 49
  • 77
2
votes
2 answers

Trouble aligning a UIView and a CAShapeLayer

I'm having trouble aligning a UIView and a CAShapeLayer. Here is sample code demonstrating the issue: import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let square =…
Trappar
  • 231
  • 2
  • 12
2
votes
1 answer

How to close triangle path?

I have drawn this shape: here is my code: /* build path */ let bottomBezierPath = UIBezierPath() //first thing draw bottom line bottomBezierPath.moveToPoint(CGPointMake(0,…
david
  • 3,310
  • 7
  • 36
  • 59
2
votes
2 answers

Circle to rectangle transformation animation

I am very new to iOS and I need to do following animation: Transformation of the circle to rectangle should be smooth, but in above animation it's not very smooth. What I did is create a circle and a rectangle using following code in this…
roledene JKS
  • 405
  • 2
  • 8
  • 12
2
votes
3 answers

Creating Triangle with UIBezierPath in Swift

I am trying to understand how to create a triangle shape with Swift. I found this code that creates a triangle. class TriangleLayer: CAShapeLayer { let innerPadding: CGFloat = 30.0 override init() { super.init() fillColor =…
senty
  • 12,385
  • 28
  • 130
  • 260
2
votes
1 answer

Drawing sublayers inside a bezier Arc

I'm trying to draw a series of vertical lines inside of an arc but I'm having trouble being able to do this. I'm trying to do this using CAShapeLayers The end result is something that looks like this. I know how to draw the curved arc and the line…
zic10
  • 2,310
  • 5
  • 30
  • 55
2
votes
2 answers

Can I access a CAShapeLayer's path property in the presentation layer?

I have a UIView subview called "starfish". It's backing layer is a CAShapeLayer who's path strokes a starfish shape. I want to do hit testing on this shape in my view controller within the enclosed path and not the view's rectangle. This is no…
Jas999
  • 111
  • 6
2
votes
1 answer

Issue with CAShapeLayer Animation iOS7

I have been struggling with an animation effect on iOS7 (8, 9 it works fine) that involves contracting a rounded rect to become a circle. To get an effect like this. But i am getting some distortion when trying to contract the circle on iOS7. My…
jarora
  • 5,384
  • 2
  • 34
  • 46
2
votes
0 answers

CAShapeLayer draw dotted line only in Bottom

Hello Guys i have been trying to Draw the Dotted line below UILabel using this code extension UIView{ func addDashedBorder() { self.layoutIfNeeded() let color = UIColor.lightGrayColor().CGColor let…
hardikdevios
  • 1,779
  • 14
  • 33
2
votes
1 answer

How do I make a UIScrollView scrollable only when touches are inside a custom shape?

I am working on creating an image collage app. And I am going to have multiple UIScrollView's. The scroll views will have boundaries with custom shapes and the user will be able to dynamically change the corners of the shapes where they…
nibelungen
  • 25
  • 5
2
votes
1 answer

CAShapeLayer rotate around the center

The layer has a shape of ring. I want it to rotate around its center. Here's my code: class ClipRotateView: UIView { override init(frame: CGRect) { super.init(frame: frame) } required init(coder aDecoder: NSCoder) { super.init(coder:…
Antimony
  • 143
  • 1
  • 9
2
votes
4 answers

CAShapeLayer mask reveal from bottom

I'm trying to create a "reveal" effect from the bottom of an image. I thought it would be as simple as setting the anchorPoint to CGPointMake(0.5, 1.0) or the contentsGravity to kCAGravityTop, but none of these options works. The current code I…
Shai Mishali
  • 9,224
  • 4
  • 56
  • 83
2
votes
1 answer

Scale a circle at same center position

I am working on scaling the circle and keep the same center position, which looks like the pulsing circle on map. AnimationView.m @property (nonatomic, strong) UIBezierPath *ovalPath; - (void)drawCircle { …
Zigii Wong
  • 7,766
  • 8
  • 51
  • 79
2
votes
1 answer

How to delete a CAShapeLayer like eraser? (Not using another layer of white colour) - adding layers using bezier path

This is what I used: UIBezierPath *_path; shapeLayer.path = _path.CGPath; shapeLayer.lineWidth =10; shapeLayer.lineCap=kCALineCapRound; UIColor *color=[dict objectForKey:@"Colors"]; shapeLayer.strokeColor = color.CGColor; shapeLayer.fillColor =…