cashapelayer

Incorrect position of CAShapeLayer

浪尽此生 提交于 2019-12-04 21:04:21
I have a UIView called viewProgress . It is the white box in the image. I want a circular progress bar, which is the green circle in the image. The progress bar should stay within the white box, but as you can see it is way off. How do I make it stay inside the viewProgress ? Here you have my animation function: func animateView() { let circle = viewProgress // viewProgress is a UIView var progressCircle = CAShapeLayer() let circlePath = UIBezierPath(arcCenter: circle.center, radius: circle.bounds.midX, startAngle: -CGFloat(M_PI_2), endAngle: CGFloat(3.0 * M_PI_2), clockwise: true)

animating strokeEnd in a CAShapeLayer using an animation block in Swift

浪子不回头ぞ 提交于 2019-12-04 16:55:06
I am attempting to trace out the shape of a path that I've place into a CAShapeLayer. In this function, the points in the points array represent the vertices of a regular polygon. The animation isn't happening, though. It's just appearing, totally animated. Here is the code: private func drawShape (point: [(x: Double, y:Double)]) { let shapeLayer = CAShapeLayer() let shapePath = UIBezierPath() shapePath.moveToPoint(CGPoint(x:point[point.count-1].x, y:point[point.count-1].y)) for i in point { shapePath.addLineToPoint(CGPoint(x:i.x, y:i.y)) } shapeLayer.path = shapePath.CGPath drawingSurface

Setting correct frame of a newly created CAShapeLayer

血红的双手。 提交于 2019-12-04 16:16:46
问题 In short: Apple does NOT set the frame or bounds for a CAShapeLayer automatically (and Apple HAS NOT implemented an equivalent of [UIView sizeThatFits] ) If you set the frame using the size of the bounding-box of the path ... everything goes wrong. No matter how you try to set it, it screws-up the path So, what's the correct way to programmatically set the frame of a newly-created CAShapeLayer with a newly-added CGPath ? Apple's docs are silent on the matter. Things I've tried, that don't

Animation CAShapeLayer

て烟熏妆下的殇ゞ 提交于 2019-12-04 15:59:10
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 = [colorGraph CGColor]; for (NSValue *value in arrOfPoints) { CGPoint pt = [value CGPointValue]; CGPathAddLineToPoint(linePath, NULL, pt.x,pt.y); }; curentGraph.path = linePath;CGPathRelease(linePath); [self.layer addSublayer:curentGraph]; and it looks like this But I have a problem. I need to animate the graph as it appears. Every point should move up from

Transforming a CAShapelayer to a specific size in swift

泪湿孤枕 提交于 2019-12-04 15:54:51
I'm trying to make a CAShapeLayer with a bezier path in it expand with a view (which is animated, of course). I am aware that I could change the size of the path with CATransform3DMakeScale(, , ) But this won't allow me to make the path an exact size (in points). Does anybody know how to do this? You would do this using good old fashioned math. Simple solution To phrase your question differently: you have something of one size (the path/shape layer), and you want to scale it so that it becomes another size. To know how much you want to scale along X and Y (separately) you divide the size you

How to draw Arc with curved edge in iOS?

南笙酒味 提交于 2019-12-04 14:01:42
In one of my application, I am trying to draw a gradient arc with rounded edges. Like the following image. This is what I have done so far using the following code. -(void)startArc { UIBezierPath *roundedArc = [self arcWithRoundedCornerAt:centerPoint startAngle:DEGREES_TO_RADIANS(-90) endAngle:DEGREES_TO_RADIANS(90) innerRadius:width-20 outerRadius:width cornerRadius:0]; CAShapeLayer *mask = [CAShapeLayer new]; [mask setPath:roundedArc.CGPath]; [mask setFrame:_outerView.bounds]; [mask setShouldRasterize:YES]; [mask setRasterizationScale:[UIScreen mainScreen].scale]; CAGradientLayer *gradient =

Swift draw shadow to a uibezier path

浪尽此生 提交于 2019-12-04 13:56:53
问题 I have a strange question. Even though I did read a lot of tutorials on how to do this, the final result only shows the bezier line, not any shadow whatsoever. My code is pretty simple : let borderLine = UIBezierPath() borderLine.moveToPoint(CGPoint(x:0, y: y! - 1)) borderLine.addLineToPoint(CGPoint(x: x!, y: y! - 1)) borderLine.lineWidth = 2 UIColor.blackColor().setStroke() borderLine.stroke() let shadowLayer = CAShapeLayer() shadowLayer.shadowOpacity = 1 shadowLayer.shadowOffset = CGSize

CAShapeLayer Shadow with UIBezierPath

為{幸葍}努か 提交于 2019-12-04 13:08:09
问题 This question continues from a previous answer. I have the following CAShapeLayer : - (CAShapeLayer *)gaugeCircleLayer { if (_gaugeCircleLayer == nil) { _gaugeCircleLayer = [CAShapeLayer layer]; _gaugeCircleLayer.lineWidth = self.gaugeWidth; _gaugeCircleLayer.fillColor = [UIColor clearColor].CGColor; _gaugeCircleLayer.strokeColor = self.gaugeTintColor.CGColor; _gaugeCircleLayer.strokeStart = 0.0f; _gaugeCircleLayer.strokeEnd = self.value; _gaugeCircleLayer.lineCap = kCALineCapRound;

How to draw a filled path/shape in different colors

时光总嘲笑我的痴心妄想 提交于 2019-12-04 12:36:28
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 many more lines of code that I would like to write to fix this problem. Is there any way to change the UIImage color other than what I have written? Would it be easier to draw the shape in context and fill it? TY. Update: The Hexagon is drawing itself the right way, but it doesn't fill right at all. Here is the code: self.Hexagon.lineWidth=10;

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

懵懂的女人 提交于 2019-12-04 09:44:08
问题 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: CFTimeInterval = 0.5 override init() { super.init() fillColor = Colors.clear.CGColor lineWidth = 5.0 path = rectanglePathStart.CGPath } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } var rectanglePathStart: