Tag: cashapelayer

限制平移手势移动到90度

如果我为前者创build了一行 在图中显示为通过CAShapeLayer连接A和B,在该行的中心我有一个UIView ,其中包含了平移手势。 如何使UIView移动到某个方向创build90度,如图所示,红线表示UIView可以移动的方向? 中点应该从线的中心开始,沿着我已经更新的图中所示的方向。

圆整视图的右上angular和左上angular?

我想弄清楚如何掩盖一个UIView,以显示一个形状,代表一个半圆形的坐在上面的广场。 基本上,这就像将边界半径应用到顶部的两个angular,将其四舍五入来创build一个弧。 我正在迅速使用,这让我疯狂。 编辑:CornerRadius不会做我想要的。 我觉得我将不得不使用CGShapeLayer,但我不知道如何创build弧。 EDIT2: EDIT3: 考虑到解释我想要的东西,提供图片,并解释说我不明白我需要做什么,或者我需要做些什么对一些人来说是不够的,这就是我所尝试的: 尝试设置layer.cornerRadius属性,同时将视图的底部向外推过屏幕,以隐藏底部的angular落显示中断,这种types的遮罩过于圆形,并没有提供适当的圆弧结果。 我试图使用UIBezierPath设置顶部的两个angular落使用views width / 2angularcornerRadii。 这也没有产生适当的结果。 在试图硬编码值到cornerRadii,我注意到,无论价值,我似乎无法获得我想要的结果。 还有什么其他的select? 或者我只是不正确地使用BezierPath? 编辑4: 这是我的原始代码。 override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) let bezierPath = UIBezierPath(roundedRect: navBarView.bounds, byRoundingCorners: [.TopLeft, .TopRight], cornerRadii: CGSizeMake(navBarView.bounds.width / 2, navBarView.bounds.width / 2)).CGPath; let shapeLayer = CAShapeLayer(); shapeLayer.bounds = navBarView.bounds shapeLayer.path = bezierPath navBarView.layer.mask = shapeLayer updateUI() // […]

在iPhone 5s以上的设备上,CAShapeLayer不会随CGAffineTransformRotate旋转

我正在创build简单的弧形图表,如下所示: – (void)drawRect:(CGRect)rect { CGFloat lineWidth = 18.5f; CGFloat margin = 11; CAShapeLayer *circleLayer = [CAShapeLayer layer]; [circleLayer setPath:[[UIBezierPath bezierPathWithOvalInRect: CGRectMake(margin + lineWidth/2, margin + lineWidth/2, CGRectGetWidth(rect) – margin * 2 – lineWidth, CGRectGetWidth(rect)- margin * 2 – lineWidth) ] CGPath]]; [circleLayer setStrokeColor:[_fillColor CGColor]]; [circleLayer setFillColor:[[UIColor clearColor] CGColor]]; [circleLayer setLineWidth:18.5f]; [circleLayer setLineCap:kCALineCapRound]; [circleLayer setStrokeEnd: _fill]; […]

如何删除CAShapeLayer沿用户拖动?

我是新来的绘画应用程序,所以请build议我有什么办法删除。 我GOOGLE了我只得到 CGContextSetBlendMode(_context, kCGBlendModeClear); 但不适用于CAShape层 UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:CGPointMake(touchPoint.x,touchPoint.y)]; [path addLineToPoint:CGPointMake(startingPoint.x,startingPoint.y)]; CAShapeLayer *shapeLayer = [CAShapeLayer layer]; shapeLayer.path = [path CGPath]; // shapeLayer.strokeColor =kCGBlendModeClear; if([UIDevice currentDevice].userInterfaceIdiom ==UIUserInterfaceIdiomPad) { shapeLayer.lineWidth = 7.0; } else { shapeLayer.lineWidth = 5.0; } shapeLayer.fillColor = [[UIColor clearColor] CGColor]; [self.layer addSublayer:shapeLayer]; [clearBeizer addObject:shapeLayer]; 请帮我删除这一层谢谢。

无法删除CAShapeLayer

我在屏幕上绘制了总共21行的测量工具。 这些线在UIViewController.view上绘制为一个图层。 我试图删除行如下。 NSLog声明证实,我正在获取所有21个CAShapeLayers,我正在寻找。 CAShapeLayer* layer = [[CAShapeLayer alloc]init]; for (UIView *subview in viewsToRemove){ if([subview isKindOfClass:[CAShapeLayer class]]){ count++; NSLog(@"%d: %@", count, subview); [layerArray addObject:layer]; } } for(CAShapeLayer *l in layerArray){ [l removeFromSuperlayer]; } 任何帮助获取这些行删除将不胜感激。 我不认为这是必要的,但如果你想看到代码在这里画线是这样的: for(int i = 0; i < numberOfColumns; i++){ CAShapeLayer *lineShape = nil; CGMutablePathRef linePath = nil; linePath = CGPathCreateMutable(); lineShape […]

如何将CAShapeLayer坐标转换为CIRectangleFeature以进行手动裁剪

我正在处理手动图像裁剪function。 为了绘制CAShapeLayer,我们使用了四个坐标topLeft,topRight,bottomRight和bottomLeft。 用户可以平移点并select裁剪区域。 我被困在将这些点转换为核心图像坐标,并进一步裁剪与CIPerspectiveTransform。

在CABasicAnimation中闪烁以进行旋转

我正在试图从一个angular度旋转一个CAShapeLayer,只要按下一个button,它就会从当前angular度开始旋转。 我正在使用委托函数animationDidStop在animation结束时设置图层的变换,因为我已经注意到animation只改变了表示层的变换而不是本身的图层。 但是在animation结束时,animation完成时,由于图层在委托函数animationDidStop中更新转换之前返回到其上一个变换,animation中会出现随机闪烁。 我如何消除闪烁? @implementation ViewController – (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag { [CATransaction begin]; [CATransaction setValue: (id) kCFBooleanTrue forKey: kCATransactionDisableActions]; self.parentLayer.transform = CATransform3DRotate(self.parentLayer.transform, DEG2RAD(60.0), 0, 0, 1); [CATransaction commit]; } – (IBAction)rotateBySixtyPressed:(id)sender { CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; animation.duration = 3.0; animation.byValue = [NSNumber numberWithFloat:DEG2RAD(60.0)]; [animation setDelegate:self]; [self.parentLayer addAnimation:animation forKey:animation.keyPath]; }

如何使CAShapeLayer中的dynamicstrokeColor? 在Swift中

我使用六个参数(活动,不活动,有线,压缩,免费和总计)。 我做了一个CAShapeLayer类,我在那里做了一个function,我可以绘制圆只是添加参数的帮助。 我制作了CGPath并且在绘制一个圆圈的函数中添加了六次。 我得到了5层到UIView 。 我做了一秒钟更新数据的定时器,但它添加其他5层到UIView 。 这是错误的方式。 我想用数据animation弧,并在一秒钟内更新。 当层变得太多设备工作缓慢。 我怎样才能做到这一点? 我在这里写了我的例子。 public class Arc { public init() { } public func addFigure(path: CGPath, fillColor: UIColor, strokeColor: UIColor, strokeStart: CGFloat, strokeEnd: CGFloat, lineWidth: CGFloat, miterLimit: CGFloat, lineDashPhase: CGFloat, layer: CALayer) -> CAShapeLayer { let shape = CAShapeLayer() shape.path = path shape.fillColor = fillColor.CGColor shape.strokeColor = […]

CAShapeLayer在animationSwift中检测触摸

我可以检测到这样一个CAShapeLayer触摸(touchesEnded): let touchLocation : CGPoint = (touch as! UITouch).locationInView(self.view) for shape in shapes{ if CGPathContainsPoint(shape.path, nil, touchLocation, false){ print("Layer touch") } } 而且我可以像这样animation化一个CAShapeLayer的path: let newShapePath = UIBezierPath(arcCenter: toPoint, radius: 20, startAngle: CGFloat(0), endAngle: CGFloat(M_PI * 2), clockwise: true).CGPath // animate the `path` let animation = CABasicAnimation(keyPath: "path") animation.toValue = newShapePath animation.duration = CFTimeInterval(duration) animation.timingFunction = […]

如何缩放CAShapeLayer

在swift中,我成功地制作了一个包含在CAShapeLayer的animationbezier path 。 我唯一的问题是实施到其他屏幕尺寸。 有谁知道我怎么可以扩大CAShapeLayer里面的path? 即使它成为原来大小的一半。