I'm building an app with some UIBezierPath instances and I want to position a circle at the beginning of two of them. In the image, it's where the arrows are pointing.
How can I achieve that assuming I have the reference to both UIBezierPath instances?
Related
Constructing custom variations of rounded rectangles is fussy business. The Swift V 5.1 answer in this thread:
Swift: UIBezierPath Stroke Animation from Center
Describes out to draw a rounded rectangle starting from the top center, so you can animate stroking it starting from that point.
It uses the UIBezierPath method addArc(withCenter:radius:startAngle:endAngle:clockwise:) to draw the corner arcs of the rounded rectangle.
Getting the code right to draw the connected series of line segments and quarter arcs requires quite a bit of care, plus some knowledge of trig to figure out the angles of the different arcs for each quadrant.
CGPath has a variation on addArc, addArc(tangent1End:tangent2End:radius:transform:), that works differently. It takes "tangent end" points that define the arc in a way that's less fussy to set up (once you figure out how it works.)
I can't find an equivalent method for UIBezierPath. Am I missing something? I guess the answer is to create a CGPath (or rather, CGMutablePath using calls to addArc(tangent1End:tangent2End:radius:transform:) and then use the UIBezierPath initializer that takes a CGPath, but that is an added step that makes the code a little bit more confusing.
It looks like there is no UIBezierPath equivalent to the CGPath method addArc(tangent1End:tangent2End:radius:transform:).
I guess the answer is to just use CGPath when you want to add arcs in the form addArc(tangent1End:tangent2End:radius:transform:), and then convert the result to a UIBezierPath using the UIBezierPath.init(cgPath:) initializer.
At first I was thinking I could write an extension of UIBezierPath that would add a addArc(tangent1End:tangent2End:radius:transform:) method to UIBezierPath, but that would get very messy, since addArc(tangent1End:tangent2End:radius:transform:) uses the current pen position in the active path to figure out the first tangent line.
I want to create a circular dial in swift. The entire circle is divided into images and I want to place those images to create a circle. Each image is clickable so that one image placed in centre of the arch could get change.
So I need to create circle using buttons in swift. Please note that I don't want to create a circular button, I want to create circle using button. Something like what is done in below link using labels.
Draw text along circular path in Swift for iOS
Suppose we have n images to arrange around the circumference of a circle of radius r. The circle is 2π radians, so use polar coordinates from the center of the circle to find the points on the circumference at angles that are multiples of 2π/n. Now center the images (buttons) at those points.
I'm trying to draw a simple shape as part of the interface of a game, and most tutorials use a UIBezierPath to define the path of a CAShapeLayer. However, I noticed that UIBezierPath already has an existing fill function.
This is probably a stupid question, but what is the difference between using that and using a separate CAShapeLayer to draw the path? Also, which one is better?
The "CA" in CAShapeLayer stands for CoreAnimation.
If you wish to animate, move, manipulate, or well, anything else to a UIBezierPath, you need to use a CALayer (or it's subclass CAShapeLayer).
UIBezierPaths are the correct thing to use if what you want is to simply "draw" - and it's usually done in draw(rect:). You can also "redraw" if you will.
But if you want persistence (and control) over a shape, turn that UIBezierPath into a CAShapeLayer.
I am drawing a UIBezierPath on a CGContext using Swift 3.0. I need the path to have random shaped border, i.e. outline - like the blue path in this image:
I haven't found anything in UIBezierPath that can help to do that. Could this be done using CGPattern or even CGPath ?
When I use CAShapeLayer and create a rectangle shape then the path starts at rectangle's origin (top-left corner) and draws clockwise. Now if I want to draw only part of the shape then I'm using strokeStart and strokeEnd properties. The problem comes when I want to draw a part consisting the path's end points. In this case the path is closed and it starts and ends on rectangle's top-left corner. When I'm setting strokeStart=0.8 and strokeEnd=0.2 I'm hoping it to draw the last section of the path and a bit from the beginning of the path. However, this is not working. Are there any ideas or tricks how to do this?
Update:
Adding an image to clarify what I mean above. I want an animation which draws a small amount of rectangle and that drawn part circles over the rectangle:
The short answer is that I don't think you can do that, at least not with a single path that will draw any of the segments in your examples. I'm pretty sure that strokeStart must be less than strokeEnd.
If you want to draw your last segment you'd need to create a custom rectangle path that started at the lower left corner and wrapped around.