Tag: cashapelayer

iOS:UIBezierPath和CAShapeLayer fillRule

我之前使用过UIBezierPath和CAShapeLayer 。 但是几乎每次都要用里面的颜色填充path中包含的对象。 但是我希望这个时候能够填充UIBezierPath包含的对象之外的颜色。 我只写了下面的简单代码,试图让我熟悉fillRule属性: 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 tried this as well: kCAFillRuleEvenOdd; myLayer.path = testPath.CGPath; myLayer.fillColor = [UIColor whiteColor].CGColor; 但是颜色仍然填充在里面。 我想知道的是,如何填补path外的颜色? 如果我在这里使用fillRule错误,我想知道是否有其他方法可以实现这一点。 提前致谢。

从CGPath修剪/减去CGPath?

我在CGPath进行了一些CGPath (带有两个圆的CAShapeLayer 。 我可以修剪/减去这样的path吗?

CALayer与CGContext,这是一个更好的devise方法?

我一直在做一些iOS绘图的实验。 为了做一个实际的练习,我写了一个BarChart组件。 下面是类图(呃,我不允许上传图片),所以让我用文字来写。 我有一个NGBarChartViewinheritance自UIView有2个协议NGBarChartViewDataSource和NGBarChartViewDelegate。 代码是在https://github.com/mraghuram/NELGPieChart/blob/master/NELGPieChart/NGBarChartView.m 为了绘制barChart,我创build了每个barChart作为不同的CAShapeLayer。 我这样做的原因有两个,首先我可以创build一个UIBezierPath并将其附加到一个CAShapeLayer对象和两个,我可以通过使用[Layer hitTest]方法轻松跟踪是否触摸barItem。 该组件工作得很好。 然而,我不习惯用我绘制barCharts的方法。 因此,这个笔记。 我需要关于以下方面的专家意见 通过使用CAShapeLayer和创buildBarItems我真的不使用UIGraphicsContext,这是一个很好的devise? 我的方法将在UIView中创build几个CALayers。 基于性能的限制,你可以在UIView中创buildCALayers的数量。 如果一个好的select是使用CGContext *方法,那么怎样才能确定一个特定的path是否被触及 从animation的angular度来看,比如当你点击它时Bar闪烁,是Layerdevise更好还是CGContextdevise更好。 非常感谢帮助。 顺便说一句,你可以自由地看我的代码和评论。 我会很乐意接受任何改善build议。 最好的,Murali

在animation边界上更改animationCAShapeLayerpath

我有一个CAShapeLayer(这是一个UIView子类的层),其path应该更新视图的bounds大小更改。 为此,我重写了图层的setBounds:方法来重置path: @interface CustomShapeLayer : CAShapeLayer @end @implementation CustomShapeLayer – (void)setBounds:(CGRect)bounds { [super setBounds:bounds]; self.path = [[self shapeForBounds:bounds] CGPath]; } 这工作正常,直到我animation的界限变化。 我想要的pathanimation沿着任何animation边界改变(在UIViewanimation块),以便形状层始终采取其大小。 由于path属性默认没有animation,所以我想出了这个: 覆盖图层的addAnimation:forKey:方法。 在其中,找出边界animation是否被添加到图层。 如果是这样,则通过复制传递给该方法的边界animation中的所有属性,创build第二个显式animation来为边界旁边的path设置animation。 在代码中: – (void)addAnimation:(CAAnimation *)animation forKey:(NSString *)key { [super addAnimation:animation forKey:key]; if ([animation isKindOfClass:[CABasicAnimation class]]) { CABasicAnimation *basicAnimation = (CABasicAnimation *)animation; if ([basicAnimation.keyPath isEqualToString:@"bounds.size"]) { CABasicAnimation *pathAnimation = [basicAnimation copy]; […]

CAShapeLayer遮罩视图

我有一个问题。 我在网上寻找答案,我不明白为什么不工作。 我必须做一些愚蠢的错误,我无法弄清楚。 如果我做: – (void)viewDidLoad { [super viewDidLoad]; UIView * view = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 300, 400)]; view.backgroundColor = [UIColor blueColor]; [self.view addSubview:view]; } 它在屏幕上创build蓝色的视图,但如果我做 – (void)viewDidLoad { [super viewDidLoad]; UIView * view = [[UIView alloc]initWithFrame:CGRectMake(10, 10, 300, 400)]; view.backgroundColor = [UIColor blueColor]; [self.view addSubview:view]; CAShapeLayer * layer = [[CAShapeLayer alloc]init]; layer.frame = CGRectMake(10, […]

如何将边框添加到带有蒙版的圆形图像

这是我的尝试: func round() { let width = bounds.width < bounds.height ? bounds.width : bounds.height let mask = CAShapeLayer() mask.path = UIBezierPath(ovalInRect: CGRectMake(bounds.midX – width / 2, bounds.midY – width / 2, width, width)).CGPath self.layer.mask = mask // add border let frameLayer = CAShapeLayer() frameLayer.path = mask.path frameLayer.lineWidth = 4.0 frameLayer.strokeColor = UIColor.whiteColor().CGColor frameLayer.fillColor = nil […]

iOS:CAShape层path转换

在对path进行基本转换之前,我已经使用了CAShape Layer从一个较小的圆圈到一个更大的圆圈。 够好的,但是我试图把一个三angular形变成一个圆圈。 它工作,但转换是奇怪的。 换句话说,从一个形状到另一个形状,它在最终形状形成之前“翻转”,“扭曲”。 形状相同,从圆形到圆形都没有问题,但形状各异,变形怪异。 我想知道这是否是预期的方式? 还是有其他的技巧或解决方法,我们可以顺利地,并成比例地使用CAShape Layer将一个形状转换成另一个不同的形状(或者是否有其他方式来做到这一点,它不一定是CAShape Layer )? 提前致谢。

创build一个只有一个对angular线的UIView

我需要创build一个UIView有左边界倾斜45度,我想知道,是否有办法实现这个编程? 在这种情况下, CATransform3D是否帮助我,因为它不是真正的“3D旋转”? 编辑 这是一个图像,解释更多我需要的输出

CAShapeLayer的框架和边界

我正在研究CAShapeLayer 。并尝试绘制非线性CAShapeLayer 。我想将帧设置为CAShapeLayer 。因此,我可以使用CGPathGetPathBoundingBox方法从CGPathRef获取帧。 这是代码: CGMutablePathRef path = CGPathCreateMutable(); CGPathAddArc(path, NULL, rect.size.width/2, rect.size.height/2, 100, (0), (M_PI_2), NO); CGPathAddArc(path, NULL, rect.size.width/2, rect.size.height/2, 100-50, (M_PI_2), (0), YES); CGPathCloseSubpath(path); CAShapeLayer* arcLayer = [[CAShapeLayer alloc]init]; arcLayer.path = path; arcLayer.frame = CGPathGetPathBoundingBox(path); arcLayer.bounds = CGPathGetPathBoundingBox(path); [self.layer addSublayer:arcLayer]; ` 请仔细参考我的代码。我已经设置相同的框架和边界到CAShapeLayer.My的问题是,如果我没有设置边界(框架相同),那么它将不会显示我的内容或它不会显示框架内我的内容。为什么?请帮助我感谢你。

如何使用线路path来绘制CALayer,如模拟橡皮擦效果?

我想通过触摸事件来模拟橡皮擦效果,以显示顶部背后的图像,例如灰色; 类似的东西: 我已经find了很长时间的解决scheme,但我做不到。 以下是我的自定义视图代码:CustomView.m: -(id)initWithCoder:(NSCoder *)aDecoder { if (self = [super initWithCoder:aDecoder]) { [self setup]; } return self; } -(id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self setup]; } return self; } -(void)setup { [self setMultipleTouchEnabled:NO]; [self setBackgroundColor:[UIColor darkGrayColor]]; self.drawingPath = [UIBezierPath bezierPath]; [self.drawingPath moveToPoint:CGPointZero]; [self.drawingPath setLineWidth:5.0]; self.image = [UIImage imageNamed:@"transformers.jpg"]; self.shapeLayer = […]