Tag: cashapelayer

使用CAShape图层绘制两条平行线

我正在画单线 CAShapeLayer *lineShape = nil; CGMutablePathRef linePath = nil; linePath = CGPathCreateMutable(); lineShape = [CAShapeLayer layer]; lineShape.lineWidth = 1.0f; lineShape.lineCap = kCALineJoinMiter; lineShape.strokeColor = [[UIColor redColor] CGColor]; CGPathMoveToPoint(linePath, NULL, x, y); CGPathAddLineToPoint(linePath, NULL, toX, toY); lineShape.path = linePath; CGPathRelease(linePath); [myView.layer addSublayer:lineShape]; 我想绘制一条平行线到这条线。 任何想法或计算? 或者是否有任何获取这一特定行的触点的代码。 其实我可以得到触摸点,当我触摸两条线之间,并从CGPathContainsPoint方法我可以得到触摸点之间的两条线,因此我想在这里创build两条平行线。

如何在iOS中使用弧形边缘绘制弧形?

在我的应用程序之一,我想绘制一个带圆angular的渐变弧。 像下面的图片 这是我迄今为止使用下面的代码所做的。 -(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 = [CAGradientLayer new]; [gradient setFrame:_outerView.bounds]; // [gradient setColors:[NSArray arrayWithObjects:(id)[[UIColor colorWithRed:0.86 green:0.91 blue:0.96 alpha:1.0f] CGColor],(id)[[UIColor colorWithRed:0.98 green:0.99 blue:0.99 alpha:1.0f] CGColor], nil]]; [gradient setColors:[NSArray arrayWithObjects:(id)[UIColor colorWithRed:0.19 […]

用CAShapeLayer和UIBezierPath剪辑屏蔽uiview

我有一个问题,使用CAShapeLayer-UIBezierPath剪辑视图,我想剪辑的内容,但我最终得到一个中风(框架)与该UIBezierPath,这是我的代码 UIBezierPath *path2Path = [UIBezierPath bezierPath]; [path2Path moveToPoint:CGPointMake(206.745, 0)]; [path2Path addLineToPoint:CGPointMake(206.745, 97.613)]; [path2Path addLineToPoint:CGPointMake(0, 97.613)]; [path2Path addLineToPoint:CGPointMake(0, 0)]; [path2Path addLineToPoint:CGPointMake(87.28, 0)]; [path2Path addCurveToPoint:CGPointMake(103.808, 12.118) controlPoint1:CGPointMake(87.28, 0) controlPoint2:CGPointMake(86.555, 12.118)]; [path2Path addCurveToPoint:CGPointMake(119.466, 0) controlPoint1:CGPointMake(121.061, 12.118) controlPoint2:CGPointMake(119.466, 0)]; [path2Path addLineToPoint:CGPointMake(206.745, 0)]; [path2Path closePath]; [path2Path addClip]; CAShapeLayer *pathLayer = [CAShapeLayer layer]; pathLayer.frame=MYVIEW.bounds; pathLayer.path = path2Path.CGPath; pathLayer.strokeColor = [[UIColor blackColor] […]

使用CAShapeLayer对象与Bezierpath绘制一条线

我正在做一个图像编辑器,可以创build不同形状的对象,如圆形,三angular形和正方形,也可以更新或删除。 所以我用CAShapeLayer来创build形状对象。 现在我也想绘制一个图像,也可以更新或删除线,所以我用bezierpath和CAShapeLayer来创build线,它工作正常。 但现在的问题是,当我想要select任何现有的线可以select任何地方接近线工具,因为CAShapeLayer也设置填充区域,这将是一条从起点到终点的直线。 我的问题是,如何使用CAShapeLayer创build没有填充区域的CAShapeLayer 。 这是我创build线的代码: CAShapeLayer *line = [CAShapeLayer layer]; // Using bezierpath to make line UIBezierPath *linePath=[UIBezierPath bezierPath]; // Creating L with line [linePath moveToPoint:point1]; [linePath addToPoint:point2]; [linePath addToPoint:point3]; line.path=linePath.CGPath; // Configure the appearence of the line line.fillColor = Nil; line.opacity = 1.0; line.strokeColor = [UIColor whiteColor].CGColor; 任何想法,这将非常感激。

animationCAShapeLayer

我用这个代码绘制一个图表: 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]; 看起来像这样 但是我有一个问题。 我需要animation显示graphics。 每一个点都应该从y = 0到y = pt.y 就像他们在这个网站上的图表一样。 我该如何为我的graphics制作animation?

需要与UIBezierPath的提示。 像Instagram注册视图的三angular形状

我正在试图创build一个像下面的图片中的instagram三angular形的贝塞尔path,但是我一定是做错了什么。 贝塞尔path不显示! – (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } -(void)viewDidLayoutSubviews{ [super viewDidLayoutSubviews]; [self drawTriangle]; } – (IBAction)closeButton:(UIButton *)sender { [self dismissViewControllerAnimated:YES completion:nil]; } – (void)drawTriangle{ UIBezierPath* trianglePath = [UIBezierPath bezierPath]; [trianglePath moveToPoint:CGPointMake(self.signUpButton.center.x, self.signUpButton.frame.origin.y + 30)]; [trianglePath addLineToPoint:CGPointMake(self.signUpButton.center.x – 10, self.imageView.frame.size.height)]; [trianglePath addLineToPoint:CGPointMake(self.signUpButton.center.x + 10, self.imageView.frame.size.height)]; UIColor *fillColor […]

正弦CAShapeLayer作为CALayer的掩码

我试图实现下一个好奇的事情:我有几个点,我想把他们与正弦波 下一个方法返回用于绘制的点arrays: – (NSArray *)plotPointsBetweenPoint:(CGPoint)pointA andPoint:(CGPoint)pointB { double H = fabs(pointB.y – pointA.y); double L = fabs(pointB.x – pointA.x); NSInteger granularity = 40; NSMutableArray *array = [NSMutableArray arrayWithCapacity:granularity + 1]; for (int i = 0; i <= granularity; ++i) { CGFloat x = M_PI*(float)i/(granularity); CGFloat y = -cosf(x); CGFloat multiplier = pointA.y > pointB.y ? […]

CABasicAnimation – 设置开始行程位置

我正在为一个基本的圈子绘制animation。 这工作正常,除了animation开始绘制在3点钟的位置。 有谁知道我可以如何使它在12点开始? self.circle = [CAShapeLayer layer]; self.circle.fillColor = nil; self.circle.lineWidth = 7; self.circle.strokeColor = [UIColor blackColor].CGColor; self.circle.bounds = CGRectMake(0, 0, 200, 200); self.circle.path = [UIBezierPath bezierPathWithOvalInRect:self.circle.bounds].CGPath; [self.view.layer addSublayer:self.circle]; CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; drawAnimation.duration = 5.0; drawAnimation.repeatCount = 1.0; drawAnimation.removedOnCompletion = NO; drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; drawAnimation.toValue = [NSNumber numberWithFloat:1.0f]; drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; […]

CAShapeLayer阴影

鉴于下面的CAShapeLayer是可能的添加像阴影下面的图像的投影? 我正在使用UIBezierPath来绘制条形图。 – (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; _gaugeCircleLayer.masksToBounds = NO; _gaugeCircleLayer.cornerRadius = 8.0; _gaugeCircleLayer.shadowRadius = 8.0; _gaugeCircleLayer.shadowColor = [UIColor blackColor].CGColor; _gaugeCircleLayer.shadowOpacity = 0.5; _gaugeCircleLayer.shadowOffset = CGSizeMake(0.0, 0.0); _gaugeCircleLayer.path […]

CGContext与CALayer

我试图在Quartz 2D上find一个句柄,并在Mac OS X开发人员的在线书籍石英二维graphics 。 一个非常基本的东西,让我困惑的是CGContext。 例如,我可以用下面的代码绘制一个简单的“U”形状,并在CAShapeLayer使用它,而无需引用CGContext 。 CAShapeLayer默认情况下是否隐含/提供了上下文? 我可能在这里混合了几个iOS / OSXgraphicsAPI,所以也许有人可以澄清我的错在哪里。 CGPoint pt1 = CGPointMake(100, 100); CGPoint pt2 = CGPointMake(150, 100); CGPoint pt3 = CGPointMake(150, 200); CGPoint pt4 = CGPointMake(190, 200); CGPoint pt5 = CGPointMake(190, 100); CGPoint pt6 = CGPointMake(210, 100); CGPoint pt7 = CGPointMake(210, 250); CGPoint pt8 = CGPointMake(100, 250); CGPoint pt9 = […]