cashapelayer

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

*爱你&永不变心* 提交于 2019-12-03 04:49:42
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: UIBezierPath { let rectanglePath = UIBezierPath() rectanglePath.moveToPoint(CGPoint(x: 0.0, y: 100.0))

CAShapeLayer filling with another CAShapeLayer as a mask

匿名 (未验证) 提交于 2019-12-03 03:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: My question is about filling animation one CAShapeLayer with another CAShapeLayer . So, I wrote some code that almost achieves my goal. I created a based layer and fill it with another. Code below: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. _shapeLayer = [CAShapeLayer layer]; [self drawBackgroundLayer]; } // my main/backgound layer - (void)drawBackgroundLayer { _shapeLayer.frame = CGRectMake(0, 0, 250, 250); _shapeLayer.lineWidth = 3; _shapeLayer.strokeColor = [UIColor

Trim/subtract CGPath from CGPath?

≡放荡痞女 提交于 2019-12-03 03:00:04
I have some CGPath (a poly with two circle) carried out on a CAShapeLayer . Can I trim/subtract paths like this? Instead of do the math, the result can be achieved at drawing time using kCGBlendModeClear . // Create the poly. CGContextBeginPath(context); CGContextMoveToPoint (context, a_.x, a_.y); CGContextAddLineToPoint (context, b_.x, b_.y); CGContextAddLineToPoint (context, c_.x, c_.y); CGContextAddLineToPoint (context, d_.x, d_.y); CGContextClosePath(context); // Draw with the desired color. CGContextSetFillColorWithColor(context, self.color.CGColor); CGContextFillPath(context); // Create

How to animate CAShapeLayer path and fillColor

匿名 (未验证) 提交于 2019-12-03 01:52:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How to animate CAShapeLayer path and fillColor? How to animate strokeEnd to show the path being drawn? and how to animate fillColor? 回答1: To animate path //setup the CAShapeLayer myShapeLayer.strokeColor = [[UIColor blueColor] CGColor]; myShapeLayer.lineWidth = 5; myShapeLayer.fillColor = [[UIColor yellowColor] CGColor]; //Display it! [self.view.layer addSublayer:myShapeLayer]; //Animate path CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; pathAnimation.duration = 1.5f; pathAnimation.fromValue =

Add a shadow to CAShapeLayer, so that the inside remains transparent

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to add a glow effect to a path, like the blue glow around (OS X) interface elements when they have focus. I used a CAShapeLayer with a (rectangular) path: self.borderLayer = [CAShapeLayer layer]; CGPathRef path = CGPathCreateWithRect(self.bounds, NULL); [self.borderLayer setPath:path]; CGPathRelease(path); In the end this gives me a transparent UIView with a border around it. (In my concrete case it's a dashed line with an additional animation, but that doesn't matter for this particular question) I played around with the shadow

CAShapeLayer’s strokeEnd doesn’t animate

匿名 (未验证) 提交于 2019-12-03 00:59:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This is the code I’m using to animate my CAShapeLayer : _progressBarLayer.strokeEnd = CGFloat(_progressToDrawForProgress(progress)) let progressAnimation = CABasicAnimation(keyPath: "strokeEnd") progressAnimation.duration = CFTimeInterval(1.0) progressAnimation.fromValue = CGFloat(self.progress) progressAnimation.toValue = _progressBarLayer.strokeEnd progressAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseIn) _progressBarLayer.addAnimation(progressAnimation, forKey: "progressAnimation") I’ve tested using the

iOS: UIBezierPath and CAShapeLayer fillRule

我是研究僧i 提交于 2019-12-03 00:47:38
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 UIBezierPath . I just wrote and ran the following simple code trying to get myself acquainted with the fillRule property: CAShapeLayer *myLayer = (CAShapeLayer*) self.layer; //size: 320 X 480 UIBezierPath *testPath = [UIBezierPath bezierPathWithOvalInRect:(CGRect){{100, 100}, 100, 100}]; //a simple circle myLayer.fillRule = kCAFillRuleNonZero; // have

CALayer vs CGContext, which is a better design approach?

倾然丶 夕夏残阳落幕 提交于 2019-12-02 23:29:52
I have been doing some experimenting with iOS drawing. To do a practical exercise I wrote a BarChart component. The following is the class diagram (well, I wasnt allowed to upload images) so let me write it in words. I have a NGBarChartView which inherits from UIView has 2 protocols NGBarChartViewDataSource and NGBarChartViewDelegate. And the code is at https://github.com/mraghuram/NELGPieChart/blob/master/NELGPieChart/NGBarChartView.m To draw the barChart, I have created each barChart as a different CAShapeLayer. The reason I did this is two fold, first I could just create a UIBezierPath and

CAShapeLayer mask view

房东的猫 提交于 2019-12-02 03:03:41
I have one problem. I look for the answers on the net and I don't understand why is not working. I must do some stupid mistake which I can't figure it out. if I make : - (void)viewDidLoad { [super viewDidLoad]; UIView * view = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 300, 400)]; view.backgroundColor = [UIColor blueColor]; [self.view addSubview:view]; } it create blue view on the screen, but if I make - (void)viewDidLoad { [super viewDidLoad]; UIView * view = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 300, 400)]; view.backgroundColor = [UIColor blueColor]; [self.view addSubview:view

Swift: Add image to CAShapeLayer

折月煮酒 提交于 2019-12-01 11:59:26
I have a CAShapeLayer with a fill color, and want to add an icon in the center of this shape: var shape = CAShapeLayer() shape.fillColor = UIColor(white: 0.90, alpha: 1).CGColor var image = UIImage(named: "some_image") shape.contents = image?.CGImage This code does compile and does show the grey shape- but no image. :( I looked into these posts, but I can't cast the CGImage like they do. add UIImage in CALayer and Display an image or UIImage with a plain CALayer Is there another way? Or a workaround to the id cast? Full code: ViewController.swift import UIKit class ViewController: