cgpath

Draw iOS 7-style squircle programmatically

守給你的承諾、 提交于 2019-11-28 04:24:20
I'm trying to find a way to draw a iOS 7-style icon 'squircle' shape programmatically, using core graphics. I'm not asking how to draw a rounded rectangle . A squircle is a superellipse: which is slightly different than a regular rounded rectangle: It's exact formula is readily available . However, I can't figure out how to draw this using, for example, a CGPath, let alone fill it, and be able to resize it rather easily. All this while being entirely exact with the formula. Quote from Wikipedia: Superellipse For n = 1/2, in particular, each of the four arcs is a Quadratic Bézier curve defined

Draw glow around inside edge of multiple CGPaths

余生颓废 提交于 2019-11-28 03:43:24
If I create a CGMutablePathRef by adding together two circular paths as shown by the left image, is it possible to obtain a final CGPathRef which represents only the outer border as shown by the right image? Thanks for any help! What you are asking for is the union of bezier paths. Apple doesn't ship any APIs for computing the union of paths. It is in fact a rather complicated algorithm. Here are a couple of links: http://www.cocoadev.com/index.pl?NSBezierPathcombinatorics http://losingfight.com/blog/2011/07/09/how-to-implement-boolean-operations-on-bezier-paths-part-3/ If you explain what you

Efficient method to draw a line with millions of points

做~自己de王妃 提交于 2019-11-28 03:36:25
I'm writing an audio waveform editor in Cocoa with a wide range of zoom options. At its widest, it shows a waveform for an entire song (~10 million samples in view). At its narrowest, it shows a pixel accurate representation of the sound wave (~1 thousand samples in a view). I want to be able to smoothly transition between these zoom levels. Some commercial editors like Ableton Live seem to do this in a very inexpensive fashion. My current implementation satisfies my desired zoom range, but is inefficient and choppy. The design is largely inspired by this excellent article on drawing waveforms

finding a point on a path

谁说我不能喝 提交于 2019-11-27 18:40:53
问题 I have an app that draws a bezier curve in a UIView and I need to find the X intersect when I set a value for Y. First, as I understand, there isn’t a way to find a point directly of a UIBezierPath but you can locate a point of a CGPath . First, if I “stroke” my UIBezierPath (as I have done in my code) is this actually creating a CGPath or do I need to take further steps to actually convert this to a CGPath ? Second, I want to find the curves intersect at X by providing the value for Y. My

Where and how to __bridge

纵然是瞬间 提交于 2019-11-27 17:24:14
I need some advice on __bridge -ing in iOS. Hopefully the SSCCE 1 below will explain the problem better than I can in words, but I need to know how I can convert a void* to an NSMutableArray* ; which __bridge variation should be used (See comment in code). Reading about the different bridges, I deduced that I would need __bridge_transfer but then I receive an EXC_BAD_ACCESS on addObject: Ultimately, I'd like to have an array of the CGPoints in the CGPath after CGPathApply has been called. #import <Foundation/Foundation.h> void _processPathElement(void* info, const CGPathElement* element) {

1. CGPathMoveToPoint' is unavailable: Use move(to:transform:) 2. 'CGPathAddLineToPoint' is unavailable: Use addLine(to:transform:)

♀尐吖头ヾ 提交于 2019-11-27 15:03:44
I have created one of my application in swift 2 in Xcode 7.3.1 . But now I have open same application in Xcode 8.0 and perform changes. Some automatic changes are done and some errors and suggestions shown I have corrected them. But I am facing issue that let path = CGMutablePath() CGPathMoveToPoint(path, nil, lineFrame.midX, lineFrame.midY) CGPathAddLineToPoint(path, nil, lineFrame.origin.x + lineFrame.width / 2, lineFrame.origin.y) I tried to create path , but shows error that CGPathMoveToPoint is unavailable: Use move(to:transform:) CGPathAddLineToPoint is unavailable: Use addLine(to

Equivalent of or alternative to CGPathApply in Swift?

此生再无相见时 提交于 2019-11-27 13:18:11
In the pre-release documentation there appears to be no Swift version of CGPathApply. Is there an equivalent or alternative? I'm trying to get all subpaths of a CGPath so that I can redraw it from a different starting point. Swift 3.0 In Swift 3.0, you can use CGPath.apply like this: let path: CGPath = ... // or let path: CGMutablePath path.apply(info: nil) { (_, elementPointer) in let element = elementPointer.pointee let command: String let pointCount: Int switch element.type { case .moveToPoint: command = "moveTo"; pointCount = 1 case .addLineToPoint: command = "lineTo"; pointCount = 1 case

Undo/Redo for drawing in iOS

寵の児 提交于 2019-11-27 09:36:34
I am working on a drawing app, I want to do Undo/Redo, for this I am saving CGPath on touches ended to NSMutableArray, But I am not understanding how I should render the CGPaths on click of Undo button EDIT1: As I am using BezierPaths, So, I first decided to go with a simple approach of just stroking this path, without CGPath, EDIT2: As my Undo is happening in segments(i,e in parts and not whole path is deleted), I decided to create an array of array, So I have made changes accordingly and now I will be drawing in CGlayer, with taking CGPath So here "parentUndoArray" is array of arrays. So I

Calculate controlPoints while drawing in iOS

六月ゝ 毕业季﹏ 提交于 2019-11-27 07:11:13
问题 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) *

Get path to trace out a character in an iOS UIFont

醉酒当歌 提交于 2019-11-27 07:07:58
Suppose I have a custom font "Foo" that I'm using in my iOS App. I've added it to my project, plist, etc. and I'm able to render UILabel s and such with it just fine. Now, if I want to find out a sequence of points that would "trace out" the letter 'P' in that font, how would I get that sequence of points? For example, suppose I wanted to use a CGPath to draw the letter 'P' slowly like a plotter would ... I just need a sequence of CGPoints in an array that if drawn as a path would draw a 'P'. I realize that for some letters like 'T', this may not make sense, since the pen would have to be