cgpath

Performance when frequently drawing CGPaths

我只是一个虾纸丫 提交于 2019-11-30 02:06:45
I am working on an iOS App that visualizes data as a line-graph. The graph is drawn as a CGPath in a fullscreen custom UIView and contains at most 320 data-points. The data is frequently updated and the graph needs to be redrawn accordingly – a refresh rate of 10/sec would be nice. So far so easy. It seems however, that my approach takes a lot of CPU time. Refreshing the graph with 320 segments at 10 times per second results in 45% CPU load for the process on an iPhone 4S. Maybe I underestimate the graphics-work under the hood, but to me the CPU load seems a lot for that task. Below is my

Get CGPath total length

人走茶凉 提交于 2019-11-30 00:34:38
I have many UIBezierPath that I am animating with CALyerAnimation @"StrokeStart" and @"strokeEnd". I wish that the animation will have the same speed for all the paths so I thougt I might use the length of the path in : DISTANCE / TIME = SPEED Is there a way to calculate the path "length" ? Thanks Shani While you can calculate Bezier path's length by integrating it numerically, it can be done much easier by dividing path into linear segments. If the segments are small enough the approximation error should be neglectable, especially that you are just trying to animate it. I'll show you function

Merge multiple CGPaths together to make one path

巧了我就是萌 提交于 2019-11-29 22:38:14
I am making a complex shape using a few CGRects and Ellipses. I would like to stroke that path once it has been created. When I stroke the path it strokes each shape. Is there a way I can merge each shape into a single path, so the stroke doesn't intersect? int thirds = self.height / 3; CGPathRef aPath = CGPathCreateMutable(); CGRect rectangle = CGRectMake((58 - 10) / 2, 46, 10, self.height - 58); CGPathAddRect(aPath, nil, rectangle); CGPathAddEllipseInRect(aPath, nil, CGRectMake((58 - 48) / 2, 0, 48, 48)); CGPathAddEllipseInRect(aPath, nil, CGRectMake((58 - 48) / 2, thirds, 48, 48));

What do the parameters to CGPathAddCurveToPoint mean?

孤街醉人 提交于 2019-11-29 18:27:12
问题 I want to build a CGPathRef programatically based on the coordinates of the Sun at different points of the day. Calculating the points is not a problem, but I want to make a CGPathRef that is smooth and thought CGPathAddCurveToPoint would be appropriate. I understand the path, transform, x and y parameters, but I'm not sure about the others. Per the Apple documentation they are the control points, and I'm guessing they are like you'd see in a vector drawing program where you can adjust the

CABasicAnimation with CALayer path doesn't animate

狂风中的少年 提交于 2019-11-29 05:34:30
I'm trying to animation the transition of a CALayer from normal corners to rounded corners. I only want to round the top corners, so I am using a UIBezierPath. Here's the code: UIRectCorner corners = UIRectCornerTopLeft | UIRectCornerTopRight; UIBezierPath* newPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(8.0f, 8.0f)]; UIBezierPath* oldPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:CGSizeMake(0.0f, 0.0f)]; CAShapeLayer* layer = [CAShapeLayer layer]; layer.frame = self.bounds; layer

Performance when frequently drawing CGPaths

别等时光非礼了梦想. 提交于 2019-11-28 22:59:17
问题 I am working on an iOS App that visualizes data as a line-graph. The graph is drawn as a CGPath in a fullscreen custom UIView and contains at most 320 data-points. The data is frequently updated and the graph needs to be redrawn accordingly – a refresh rate of 10/sec would be nice. So far so easy. It seems however, that my approach takes a lot of CPU time. Refreshing the graph with 320 segments at 10 times per second results in 45% CPU load for the process on an iPhone 4S. Maybe I

Get CGPath total length

假如想象 提交于 2019-11-28 21:26:33
问题 I have many UIBezierPath that I am animating with CALyerAnimation @"StrokeStart" and @"strokeEnd". I wish that the animation will have the same speed for all the paths so I thougt I might use the length of the path in : DISTANCE / TIME = SPEED Is there a way to calculate the path "length" ? Thanks Shani 回答1: While you can calculate Bezier path's length by integrating it numerically, it can be done much easier by dividing path into linear segments. If the segments are small enough the

Calculate controlPoints while drawing in iOS

旧街凉风 提交于 2019-11-28 12:49:40
I am working on a drawing app, where user can draw/write with his finger or stylus. For this I have referred code from https://github.com/yusenhan/Smooth-Line-View , in my application. The problem which I am facing is that, the writing sometimes when you write very closely is not very smooth. So I think, I am making some mistake in getting the control point. Below is my code //Find the midpoint CGPoint midPoint(CGPoint p1, CGPoint p2) { return CGPointMake((p1.x + p2.x) * 0.5, (p1.y + p2.y) * 0.5); } #pragma mark Gesture handle -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

CAShapeLayer Animating Path Glitches / Flickers (From Ellipse to Rect and back)

被刻印的时光 ゝ 提交于 2019-11-28 09:22:46
I am running into an issue when I create an explicit animation to change the value of a CAShapeLayer's path from an ellipse to a rect. In my canvas controller I setup a basic CAShapeLayer and add it to the root view's layer: CAShapeLayer *aLayer; aLayer = [CAShapeLayer layer]; aLayer.frame = CGRectMake(100, 100, 100, 100); aLayer.path = CGPathCreateWithEllipseInRect(aLayer.frame, nil); aLayer.lineWidth = 10.0f; aLayer.strokeColor = [UIColor blackColor].CGColor; aLayer.fillColor = [UIColor clearColor].CGColor; [self.view.layer addSublayer:aLayer]; Then, when I animate the path I get a strange

iOS Core Graphics: Draw ONLY shadows of a CGPath

萝らか妹 提交于 2019-11-28 04:34:14
I am drawing a simple path in iOS 5 with Core Graphics: CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint( path, NULL, center.x , topMargin ); CGPathAddLineToPoint(path, NULL, center.x+20, topMargin+50); CGPathAddLineToPoint(path, NULL, center.x , topMargin+40); CGPathAddLineToPoint(path, NULL, center.x-20, topMargin+50); CGPathAddLineToPoint(path, NULL, center.x , topMargin ); Now i want to fill it in Overlay mode like so: [[UIColor colorWithRed:0 green:0 blue:0 alpha:0.4] setFill]; CGContextAddPath(context, path); CGContextSetBlendMode (context, kCGBlendModeOverlay);