Tag: uibezierpath

在UIScrollView的子视图中绘制一个网格分配巨大的内存

我试图在UIScrollView中创build一个UIView,其中只包含一个由UIBezierPath或使用CG函数淹没的简单网格(行为行和列)。 问题是,当我有更大的内容大小的UIScrollView(以及更大的子视图),在绘制网格时,分配了大量的内存(50MB或更多)。 UIViewController其中包括整个场景只是UIScrollView – 在viewDidLoad中添加子视图: @interface TTTTestViewController() @property (weak, nonatomic) IBOutlet UIScrollView *scrollView; @end @implementation TTTTestViewController -(void)viewDidLoad { [super viewDidLoad]; // create the subview TTTTestView *testView = [[TTTTestView alloc] init]; [self.scrollView addSubview:testView]; //set its properties testView.cellSize = 50; testView.size = 40; // set the content size and frame of testView by the properties self.scrollView.contentSize = […]

Swift:如何将点添加到封闭的CGPath?

我想让SKSpriteNodes沿着字母轮廓移动。 我有很多字母,但这里有一个例子: 我希望这个精灵跟着红线。 我发现这个答案主要涵盖了我的问题: 获取path在iOS UIFont中追踪一个字符 答案来自这个良好的工作示例代码: let font = UIFont(name: "HelveticaNeue", size: 64)! var unichars = [UniChar]("P".utf16) var glyphs = [CGGlyph](count: unichars.count, repeatedValue: 0) let gotGlyphs = CTFontGetGlyphsForCharacters(font, &unichars, &glyphs, unichars.count) if gotGlyphs { let cgpath = CTFontCreatePathForGlyph(font, glyphs[0], nil)! let path = UIBezierPath(CGPath: cgpath) print(path) XCPlaygroundPage.currentPage.captureValue(path, withIdentifier: "glyph \(glyphs[0])") } 然而,我仍然遇到一个问题,因为我的精灵并没有完成所有字母的字母的完整path,而是例如在这里“P”停止(从底部开始): 我尝试添加一些点,如下所示: CGPathAddLineToPoint(path, […]

重新定位/调整UIBezierPath的大小

我有一个可拖动的视图,其上有一个遮罩层。 遮罩层上有一个UIBezierPath,它使视图上的区域透明/透明(我想要的效果)。 我的最终目标是通过传递一个基于我的视图和另一个矩形(基本上我想隐藏相交的区域)的交点计算出来的CGRect来改变path的位置和大小(而不是掩模层!)。 1)我如何创build我的面具和path(在我的视图上创build一个透明的矩形): self.maskLayer = [CAShapeLayer layer]; self.maskLayer.frame = self.contentView.bounds; //default path rect CGRect const rect = CGRectMake(CGRectGetMidX(self.contentView.bounds) , CGRectGetMidY(self.contentView.bounds), 50,50); path = [UIBezierPath bezierPathWithRect:rect]; [path appendPath:[UIBezierPath bezierPathWithRect:self.contentView.frame]]; self.maskLayer.path = path.CGPath; self.maskLayer.fillRule = kCAFillRuleEvenOdd; self.contentView.layer.mask = self.maskLayer; 2)我的问题是,我找不到调整path大小/重新定位的方法。 我在网上search,但找不到任何解决scheme。 这个代码不起作用,但是我能想到的是: //runs while the view is being dragged(using UIPanGestureRecognizer) -(void)move{ CGRect intersectedRect = CGRectIntersection(self.frame, self.productView.frame); […]

animation贝塞尔曲线点

我正在试图使用Paintcode(伟大的应用程序,顺便说一句)制作一个贝塞尔曲线,并在“drawRect”方法中绘制自定义的UIView。 绘图工作正常,但我想要在贝塞尔曲线单一点的animation。 这是我的非工作方法: -(void)animateFlame{ NSLog(@"Animating"); // Create the starting path. Your curved line. //UIBezierPath * startPath; // Create the end path. Your straight line. //UIBezierPath * endPath = [self generateFlame]; //[endPath moveToPoint: CGPointMake(167.47, 214)]; int displacementX = (((int)arc4random()%50))-25; int displacementY = (((int)arc4random()%30))-15; NSLog(@"%i %i",displacementX,displacementY); UIBezierPath* theBezierPath = [UIBezierPath bezierPath]; [theBezierPath moveToPoint: CGPointMake(167.47, 214)]; [theBezierPath addCurveToPoint: […]

如何从UIBezierPath中生成CGPoint数组(按给定path触摸滑动对象)

我有一个UIBezierPath(弯曲像'8',只有4点),我需要做一些CGPoint数组。 有任何想法吗? 感谢名单! 编辑: 我有我的bezier初始化那样 -(void) initBezier { theBezierPath = [UIBezierPath bezierPath]; [theBezierPath moveToPoint:P(211.00, 31.00)]; [theBezierPath addCurveToPoint:P(870.00, 191.00) controlPoint1:P(432.00, -11.00) controlPoint2:P(593.00, 209.00)]; [theBezierPath addCurveToPoint:P(731.00, 28.00) controlPoint1:P(1061.95, 178.53) controlPoint2:P(944.69, 5.78)]; [theBezierPath addCurveToPoint:P(189.00, 190.00) controlPoint1:P(529.00, 49.00) controlPoint2:P(450.00, 189.00)]; [theBezierPath addCurveToPoint:P(211.00, 31.00) controlPoint1:P(-33.01, 190.85) controlPoint2:P(71.00, 37.00)]; } 和我一起animation的对象 anim = [CAKeyframeAnimation animationWithKeyPath:@"emitterPosition"]; anim.path = theBezierPath.CGPath; anim.calculationMode = kCAAnimationCubicPaced; […]

从UIBezierpath获取积分

我通过这样做了上面的BezierPath://位置是用户触摸屏幕的地方。 //位置将是图的最大值CGPoint origin = CGPointMake(xStart,620.0); CGPoint endpt = CGPointMake(xEnd,620.0); CGPoint midpt1 = midPointForPoints(origin,location); CGPoint midpt2 = midPointForPoints(location,endpt); UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:origin]; [path addQuadCurveToPoint:location controlPoint:CGPointMake(midpt1.x, midpt1.y+50)]; [path addQuadCurveToPoint:endpt controlPoint:CGPointMake(midpt2.x, midpt2.y+50)]; [shapeLayer setPath:path.CGPath]; 现在,我想检索位于path上的某些x坐标的y坐标。 例如,给定x = 0.0,我想得到y = 0.0,或者给定x = 300.0,y = 50.0。 我看了一些像这个问题和示例代码的引用,我仍然不确定。 更新:基本上,我想要做这样的事情。 更新:继方达的build议: 给定方程 X = (1-t)^2*X0 + 2*t*(1-t)*X1 + t^2 […]

iOS – 使用CAShapeLayer绘制圆的简单方法

在如何绘制一个光滑的圆圈 , …绘制圆圈和…绘制填充圈子的问题和答案是非常广泛的,包含很多不必要的步骤,使用的方法并不总是最容易重新创build或pipe理。 什么是一个简单的方法来绘制一个圆圈,并将其添加到我的UIView ?

如何将UIBezierPath带到MKAnnotation对象的后面?

在我的应用程序,用户在地图上绘制一个形状,并使用UIBeizerPath我正在绘制该path。 然后根据path的坐标,我显示只在该区域的结果。 一切都很好,除了现在注释掉落在地图视图上时,引脚看起来像是在path的后面,这意味着path看起来在前面。 我正在使用此代码来显示注释和path: -(void)clearAnnotationAndPath:(id)sender { [_mapView removeAnnotations:_mapView.annotations]; path = [UIBezierPath bezierPath]; [shapeLayer removeFromSuperlayer]; } – (void)handleGesture:(UIPanGestureRecognizer *)gesture { CGPoint location = [gesture locationInView:_pathOverlay]; if (gesture.state == UIGestureRecognizerStateBegan) { shapeLayer = [[CAShapeLayer alloc] init]; shapeLayer.fillColor = [[UIColor clearColor] CGColor]; shapeLayer.strokeColor = [[UIColor greenColor] CGColor]; shapeLayer.lineWidth = 5.0; //[_mapView.layer addSublayer:shapeLayer]; [pathOverlay.layer addSublayer:shapeLayer]; path = [UIBezierPath bezierPath]; […]

用UIBezierPath画一条线

第一次使用BezierPaths,想知道这个函数实际上应该如何实现。 目前贝塞尔path在图像的框架内移动,而不是在屏幕上绘图。 有没有更好的方法来做到这一点? func drawLineFromPoint(start : CGPoint, toPoint end:CGPoint, ofColor lineColor: UIColor, inView view:UIView) { var maxWidth = abs(start.x – end.x) var maxHeight = abs(start.y – end.y) var contextSize : CGSize! if maxWidth == 0 { contextSize = CGSize(width: 1, height: maxHeight) }else { contextSize = CGSize(width: maxWidth, height: 1) } //design the path UIGraphicsBeginImageContextWithOptions(contextSize, […]

为什么CGSizetypes的cornerRadii参数在 – ?

我无法弄清楚这一点…我正在玩 -[UIBezierPath bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:]就像这样: bezierPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(10, 10, 80, 80) byRoundingCorners:(UIRectCornerBottomLeft) cornerRadii:CGSizeMake(20, 20)]; 它按预期工作。 但是,如果我用cornerRadii:CGSizeMake( cornerRadii:CGSizeMake(20, 5)或CGSizeMake(20, 40)代替cornerRadii:CGSizeMake(20,20 CGSizeMake(20, 40) ,则没有区别。 为什么是cornerRadii CGSize而不是CGFloat呢? 什么是CGSize.height ? 任何想法和build议将不胜感激:)