cashapelayer

CGContext vs CALayer

爷,独闯天下 提交于 2019-11-29 10:18:51
问题 I'm trying to get a handle on Quartz 2D and looking at the online book Quartz 2D Graphics for Mac OS X Developers. One very basic thing that is confusing me is the CGContext. For example, I can draw a simple "U" shape with the code below and use it in a CAShapeLayer without referencing a CGContext . Is the context implied/provided by default by the CAShapeLayer ? I'm probably mixing up several iOS/OSX graphics APIs here so maybe someone can clarify where I am going wrong. CGPoint pt1 =

How to draw line on Image Pattern exactly

杀马特。学长 韩版系。学妹 提交于 2019-11-29 09:26:41
问题 I have a UIImageView. Inside that I am drawing a line wit user touch event. Problem is that a line can be drawn anywhere in UIImageview , but I like to draw line with image pattern only. For example, look at this image. I need to draw line on image pattern only. This is my code: -(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; touchPoint = [touch locationInView:self.imgColor]; UIBezierPath *path = [UIBezierPath

touchesMoved drawing in CAShapeLayer slow/laggy

旧城冷巷雨未停 提交于 2019-11-29 07:24:46
As was suggested to me in a prior StackOverflow question, I'm trying to improve my drawing method for letting my user draw lines/dots into a UIView. I'm now trying to draw using a CAShapeLayer instead of dispatch_async. This all works correctly, however, drawing into the CAShapeLayer continuously while touches are moving becomes slow and the path lags behind, whereas my old (inefficient I was told) code worked beautifully smooth and fast. You can see my old code commented out below. Is there any way to improve the performance for what I want to do? Maybe I'm overthinking something. I'd

Draw circle with UIBezierPath

梦想与她 提交于 2019-11-28 21:32:53
I'm trying to draw a circle using UIBezierPath addArcWithCenter method : UIBezierPath *bezierPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0., 0., 100., 100.)]; [bezierPath addArcWithCenter:center radius:0. startAngle:0 endAngle:2 * M_PI clockwise:YES]; CAShapeLayer *progressLayer = [[CAShapeLayer alloc] init]; [progressLayer setPath:bezierPath.CGPath]; [progressLayer setStrokeColor:[UIColor colorWithWhite:1. alpha:.2].CGColor]; [progressLayer setFillColor:[UIColor clearColor].CGColor]; [progressLayer setLineWidth:.3 * self.bounds.size.width]; [progressLayer setStrokeStart:

CAShapeLayer的path动画

前提是你 提交于 2019-11-28 21:15:05
CAShapeLayer的path动画 效果 源码 https://github.com/YouXianMing/Animations // // CAShapeLayerPathController.m // Animations // // Created by YouXianMing on 15/11/17. // Copyright © 2015年 YouXianMing. All rights reserved. // #import "CAShapeLayerPathController.h" #import "PathView.h" #import "UIView+SetRect.h" #import "GCD.h" @interface CAShapeLayerPathController () @property (nonatomic, strong) PathView *pathView; @property (nonatomic, strong) GCDTimer *timer; @property (nonatomic, strong) CAShapeLayer *lineShapeLayer; @property (nonatomic, strong) CAShapeLayer *fillShapeLayer; @property (nonatomic)

iOS Bezier曲线

本秂侑毒 提交于 2019-11-28 20:24:17
https://www.jianshu.com/p/2316f0d9db65 1. Bezier曲线 相关软件:PaintCode:可以直接画图,软件根据图像生产Bezier曲线 相关概念:UIBezierPath和CGPath 方法1:- (void)moveToPoint:(CGPoint)point; //设置Bezier曲线起始点;对应CGPath方法:CG_EXTERN void CGPathMoveToPoint(CGMutablePathRef __nullable path,const CGAffineTransform * __nullable m, CGFloat x, CGFloat y) 方法2:- (void)addLineToPoint:(CGPoint)point; // 线性Bezier曲线终点;对应CGPath方法:CG_EXTERN void CGPathAddLineToPoint(CGMutablePathRef __nullable path,const CGAffineTransform * __nullable m, CGFloat x, CGFloat y) 函数:B(t) = (1-t)*P0 + t*P1;( 0 ≤ t ≤1 ) 方法3:- (void)addQuadCurveToPoint:(CGPoint)endPoint

Animating CAShapeLayer size change

瘦欲@ 提交于 2019-11-28 18:24:35
I am drawing a circle, with an initial radius of 200 self.circle = [CAShapeLayer layer]; self.circle.fillColor = nil; self.circle.strokeColor = [UIColor blackColor].CGColor; self.circle.lineWidth = 7; self.circle.bounds = CGRectMake(0, 0, 2 * radius, 2 * radius); self.circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.radius, self.radius) Can anyone please tell me how to animate a change to a radius of 100? This is how I ended up doing it: UIBezierPath *newPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(newRadius, newRadius) radius:newRadius startAngle:(-M_PI/2)

UIImagePickerController editing view circle overlay

徘徊边缘 提交于 2019-11-28 17:06:04
I've been able to get pretty far with what I've been wanting to accomplish, and that's to replicate iOS's built in circular photo cropper for the built in contacts app. However, I'm stuck at trying to get my CAShapeLayers made correctly. I'm trying to make a transparent 320 px diameter circle and the rest of the view filled with an 0.9 alpha black background. The circle and rectangle are in the right place, but, the circle is not completely transparent like I need it to be. I'm lost as to how to fix this. I appreciate your help! Code and screenshot: - (void)navigationController:

Centering CAShapeLayer within UIView Swift

会有一股神秘感。 提交于 2019-11-28 10:10:31
问题 I'm having trouble centering CAShapeLayer within a UIView. I've search and most solutions are from pre 2015 in Obj C or haven't been solved. Attached is what the image looks like. When I inspect it, its inside the red view, but idk why its not centering. I've tried resizing it but still doesn't work. let progressView: UIView = { let view = UIView() view.backgroundColor = .red return view }() //MARK: - ViewDidLoad override func viewDidLoad() { super.viewDidLoad() view.addSubview(progressView)

iOS animate/morph shape from circle to square

巧了我就是萌 提交于 2019-11-28 07:00:15
I try to change a circle into a square and vice versa and I am almost there. However it doesn't animates as expected. I would like all corners of a square to be animated/morphed at the same time but what I get is the following: I use CAShapeLayer and CABasicAnimation in order to animate shape property. Here is how I create the circle path: - (UIBezierPath *)circlePathWithCenter:(CGPoint)center radius:(CGFloat)radius { UIBezierPath *circlePath = [UIBezierPath bezierPath]; [circlePath addArcWithCenter:center radius:radius startAngle:0 endAngle:M_PI/2 clockwise:YES]; [circlePath addArcWithCenter