uibezierpath

How to create several UIButtons along a path/BezierCurve?

浪子不回头ぞ 提交于 2019-11-29 09:02:23
How can I create objects along a path/BezierCurve? In other words, how can I create several UIButtons along a given path, with a given interval along that same path? I have seen dozens of questions about moving objects. But I need a solution to actually create them. I would like to go along the path and create an object for every X points/distance. Like this: ....@....@....@....@.... In this case, for every 4 points, get the position, and create a UIButton there. iOS doesn't have a public API that directly gives you points spaced along a path. But there is a roundabout way to do it. Suppose

iOS核心绘图

拈花ヽ惹草 提交于 2019-11-29 08:36:31
1.Quartz 2D(Core Graphics) 苹果公司使用C语言编写的一套绘图引擎(一组能够实现绘图API),即可以在iOS中使用,也可以在Mac OS X上使用 step1:自定义一个类,继承自UIView step2:重写 类中的 drawRect 方法 - ( void )drawRect:( CGRect )rect { //获取已经存在的绘图上下文对象 //系统最终会将绘图上下文中记录的数据编程图像 //为了影响最终绘制出来的结果,所以,就需要修改 //唯一的绘图上下文对象中记录的数据 CGContextRef context = UIGraphicsGetCurrentContext(); CGContextMoveToPoint(context, 40 , 40 ); CGContextAddLineToPoint(context, 40 , 140 ); CGContextAddLineToPoint(context, 140 , 40 ); CGContextAddLineToPoint(context, 40 , 40 ); //设置描边的颜色 CGContextSetStrokeColorWithColor(context,[[ UIColor redColor] CGColor]); CGContextSetFillColorWithColor

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

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

How to Draw a Bezier Curve in UIView

跟風遠走 提交于 2019-11-29 05:15:09
I need to make a curve in a UIView as displayed in the image below. I have to use UIBezierPath . Kindly help me out with this. I also want to know how to flip the curve from the horizontal axis, so that I have the arc at the top and the base at the bottom. To draw a solid filled in arc within a particular CGSize , you can define a UIBezierPath like so: - (UIBezierPath * _Nullable)pathOfArcWithinSize:(CGSize)size { if (size.width == 0 || size.height <= 0) return nil; CGFloat theta = M_PI - atan2(size.width / 2.0, size.height) * 2.0; CGFloat radius = self.bounds.size.height / (1.0 - cos(theta));

How to simplify a single complex UIBezierPath polygon in iOS

半腔热情 提交于 2019-11-29 04:33:10
Problem: I have a user generated polygon (via registering user's touches on screen) which can be simple or complex (complex means having unknown number of intersections) and I want to have a simple polygon resulting from the same points on the original polygon, something like an outline or a contour if you will. Possible solutions: I have found this , but it is a JavaScript solution and this is a perfect illustration of what I need but in ActionScript! I don't need the Path itself, the points will suffice. How would you approach such problem? Update: As I was looking further around, I have

UIBezierPath: How to add a border around a view with rounded corners?

自古美人都是妖i 提交于 2019-11-29 01:27:37
I am using UIBezierPath to have my imageview have round corners but I also want to add a border to the imageview. Keep in mind the top is a uiimage and the bottom is a label. Currently using this code produces: let rectShape = CAShapeLayer() rectShape.bounds = myCell2.NewFeedImageView.frame rectShape.position = myCell2.NewFeedImageView.center rectShape.path = UIBezierPath(roundedRect: myCell2.NewFeedImageView.bounds, byRoundingCorners: .TopRight | .TopLeft, cornerRadii: CGSize(width: 25, height: 25)).CGPath myCell2.NewFeedImageView.layer.mask = rectShape I want to add a green border to that

Why is cornerRadii parameter of CGSize type in -[UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:]?

故事扮演 提交于 2019-11-29 00:21:23
问题 I can't figure this out... I'm playing with -[UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:] as such: bezierPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(10, 10, 80, 80) byRoundingCorners:(UIRectCornerBottomLeft) cornerRadii:CGSizeMake(20, 20)]; And it works as expected. But if I replace cornerRadii:CGSizeMake(20, 20) with, say, cornerRadii:CGSizeMake(20, 5) or CGSizeMake(20, 40) , there's no difference. Why is cornerRadii CGSize and not CGFloat then? What

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

Why does giving addArcWithCenter a startAngle of 0 degrees make it start at 90 degrees?

牧云@^-^@ 提交于 2019-11-28 20:15:06
问题 I'm creating a CAShapeLayer to use as a mask for a UIView 's layer. I'm using a UIBezierPath to draw the shape layer. It's working fine, except I'm getting some odd results when I draw. The geometry is not behaving as expected. I'm trying to draw simple "pie slice" in the upper right corner: #define degreesToRadians(x) ((x) * M_PI / 180.0) ... // "layer" refer's to the UIView's root layer CAShapeLayer *maskLayer = [CAShapeLayer layer]; maskLayer.frame = layer.presentationLayer ? (