Tag: 核心graphics

如何获得弧点?

我正在核心animation和核心graphics。我正在绘制一个圆弧与中心(0,0)。现在我想绘制线后弧。我可以绘制弧,但后来我无法得到两个不同的弧点。我怎么得到它?这是代码: CGMutablePathRef retPath = CGPathCreateMutable(); CGPathMoveToPoint(retPath, NULL, 20, 0); CGPathAddLineToPoint(retPath, NULL, 75,10); CGPathAddArc(retPath, NULL, 75, 10, 20, 240, 360, YES); return retPath; 请帮助我。感谢你。提示也将不胜感激。

bezierPathWithRoundedRect不是完美的圈子

我画圈有一些问题: 这个简单的代码表明: – (void)drawRect:(CGRect)rect { self.layer.sublayers = nil; CGFloat radius = self.frame.size.width/2; circle = [CAShapeLayer layer]; circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.width) cornerRadius:radius].CGPath; circle.fillColor = [UIColor clearColor].CGColor; circle.strokeColor = [UIColor redColor].CGColor; circle.lineWidth = 4; [self.layer addSublayer:circle]; CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; drawAnimation.duration = 1.0; // "animate over 10 seconds or so.." drawAnimation.repeatCount = 1.0; […]

iOS:将UITableView呈现为PDF

我已经写了pdfGenerator类来呈现整个UITableView来生成PDF。 用法: [pdfGenerator createPDFFromTableview:self.tableView]; 类方法: – (void)createPDFFromTableview:(UITableView *)tableview { [tableview scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO]; [self renderTableView:tableview]; int rows = [tableview numberOfRowsInSection:0]; int numberofRowsInView = 17; for (int i = 0; i < rows/numberofRowsInView; i++) { [tableview scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:(i+1)*numberofRowsInView inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO]; [self renderTableView:tableview]; } } – (void)renderTableView:(UITableView*)tableview { UIGraphicsBeginImageContext(tableview.frame.size); [tableview.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *tableviewImage = […]

EXC_BAD_ACCESS,同时使用CoreAnimation

我使用CoreAnimation来animationUIImageView(曲线贝塞尔animation)。 这里是我的代码: CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; pathAnimation.calculationMode = kCAAnimationCubic; pathAnimation.fillMode = kCAFillModeForwards; pathAnimation.removedOnCompletion = NO; CGPoint endPoint = originalPosition; UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:star.layer.position]; [path addQuadCurveToPoint:endPoint controlPoint:CGPointMake(star.layer.position.x, endPoint.y)]; pathAnimation.path = path.CGPath; [star.layer addAnimation:pathAnimation forKey:@"moveToScorebarAnimation"]; 结果,我得到了stacktrace的EXC_BAD_ACCESS(code = 2,address = 0x0) : CoreGraphics`CG::Path::apply(void*, void (*)(void*, CGPathElementType, CGPoint const*)) const: 0x613c06: pushl %ebp 0x613c07: movl […]

iPhone如何使两个连接的线跟随到的位置?

我用核心graphics和graphics做了一个讲话泡泡的尾巴 讲话布雷的尾巴应该移动到任何一点,如我所愿。 问题是当尾巴的末端部分(尖尖的部分)向下时,它工作正常。 但是,当泡沫倒挂时,就像泡沫部分在底部,尾部是在上面 顶部,尾部2连线互相交叉,形成一个X,当它应该是/ 可以someonle请帮我吗? double angle(CGPoint p1, CGPoint p2) { //BOOL bRev = TRUE; double dx = p2.x – p1.x; double dy = p2.y – p1.y; if (dx == 0 && dy == 0) return 0.0 if (dy == 0) { if (dx > 0) return 0.0; else return M_PI; } if (dx […]

拉伸的形状,以适应框架?

我有一个应用程序,我正在绘制一个特殊的椭圆,我做了一系列的贝塞尔path如下: CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); CGMutablePathRef pPath_0 = CGPathCreateMutable(); CGPathMoveToPoint(pPath_0, NULL, 515.98,258.24); CGPathAddCurveToPoint(pPath_0, NULL, 515.98,435.61,415.54,515.98,258.24,515.98); CGPathAddCurveToPoint(pPath_0, NULL, 100.94,515.98,0.50,435.61,0.50,258.24); CGPathAddCurveToPoint(pPath_0, NULL, 0.50,80.86,100.94,0.50,258.24,0.50); CGPathAddCurveToPoint(pPath_0, NULL, 415.54,0.50,515.98,80.86,515.98,258.24); CGPathCloseSubpath(pPath_0); CGContextSetRGBFillColor(context, 1.0000, 1.0000, 1.0000, 1.0000); CGContextSetRGBStrokeColor(context,0.0000,0.0000,0.0000,1.0000); CGContextSetLineWidth(context, 1); CGContextSetMiterLimit(context, 10.0000); CGContextAddPath(context, pPath_0); CGContextDrawPath(context, kCGPathFillStroke); CGPathRelease(pPath_0); CGContextRestoreGState(context); 我想知道,在核心graphics中,有没有什么方法可以把我刚刚创build的形状横向和纵向拉伸,使其完全符合其视图框架? IE浏览器,所以我不必手动进入我所有的观点和价值观,并写在视图边界? 我知道这种形状不会那么困难,但我有一些更复杂的形状,更费时间,我宁愿避免这样做。

画一个CGlayer到另一个CGlayer

我使用两个CGlayers进行绘制,Layer1和Layer2,我绘制到Layer1和触摸结束,我将数据转移到Layer2,并清除Layer1,并在我的drawRect,方法,我画两个层的上下文。 点击删除button,我将绘图从Layer2转移到Layer1,然后我删除layer1,但触摸结束,我不转移到Layer2,因为我只擦除Layer1 在笔上点击如果擦除发生,我将绘图从Layer1转移到Layer2,否则以前的绘图可能会消失。 在代码中,它的样子 – (void)eraserButtonClicked { CGContextRef layerContext1 = CGLayerGetContext( self.layer1); CGContextClearRect(layerContext1, self.bounds); CGContextDrawLayerInRect(layerContext1, self.bounds, self.layer2); CGContextRef layerContext = CGLayerGetContext(self.layer2 ); CGContextClearRect(layerContext, self.bounds); } – (void)pen1ButtonClicked { CGContextRef layerContext = CGLayerGetContext(self.layer2 ); CGContextClearRect(layerContext, self.bounds); CGContextDrawLayerInRect(layerContext, self.bounds, self.layer1); CGContextRef layerContext1 = CGLayerGetContext( self.layer1); CGContextClearRect(layerContext1, self.bounds); } 所以我把这个图层从一个图层转移到另一个图层,但是会发生什么 1)如果我画一条线,那么我点击擦除button,然后不擦除,如果我再次点击笔画,并没有画任何东西,如果我再次点击擦除button,现在当我试图擦除整个绘图消失 2)但是,如果我画线,然后点击擦除button,并删除线,然后再转移到笔button,画一条线,再次转到擦除button,并尝试擦除,它完美的工作。

适合UIBezierPath / CGPath圈

我需要将任意形状的pathassembly到一个圆的内部。 我可以通过计算大小,构build目标矩形,然后缩放path以适合目标矩形,来适应圆的矩形path。 let targetSize = circleDiameter / sqrt(2) let destRect = CGRect(x: 0, y: 0, width: targetSize, height: targetSize) // … Scale the path to the rect, using boundingBox of path. 但是扩展过程不是问题; 这真的是如何计算所需的规模。 基于边界框的方法对于非矩形形状提供了很差的适应性,并且对于诸如圆形的形状很不适合。 任何人都可以提出一种方法来适应任何一个圆的内部path? 谢谢。 [编辑 – 以后大量的研究] 在这个图像中可以看到问题: 蓝色矩形表示原始图像,修剪到path。 红色圆圈是最小的边界圆。 绿色矩形表示边界圆的边界框。 我需要计算红圈,所以我可以用它来缩放path。 原来这就是所谓的最小包围圆问题(AKA最小的围合圆)。 唉,我找不到任何已知algorithm的Swift或Objective-C实现,并可能需要解决一些Java / JS / C ++代码。 如果有人能节省我的时间,请做! 温暖的模糊入境。 [另一个编辑,时间飞逝] 从中国的angular度来看,这是一个相当“有趣”的问题。 […]

添加笔划后,文字变得不可见

我有下一个问题(示例代码如下): 我使用CATextLayer和NSAttributedString来显示风格化文本。 所有的工作正常,直到我添加了中风的属性。 当我添加中风 – 文字变得不可见,并在显示中,我只能看到中风。 请,我不明白会发生什么,为什么我不能同时使用文字和笔画? 谢谢。 UIFont* font = [UIFont fontWithName: size:]; UIColor* strokeColor = [UIColor colorWithRed: green: blue: alpha:1.f]; UIColor* foregroundColor = [UIColor colorWithRed: green: blue: alpha:1.f]; CTFontDescriptorRef fontDescriptor = CTFontDescriptorCreateWithNameAndSize(…); CTFontRef ctFont = CTFontCreateWithFontDescriptor(…); NSDictionary* attributes = [NSDictionary dictionaryWithObjectsAndKeys: strokeWidth, kCTStrokeWidthAttributeName, [strokeColor CGColor], kCTStrokeColorAttributeName, ctFont, kCTFontAttributeName, [foregroundColor CGColor], kCTForegroundColorAttributeName, nil]; NSAttributedString* […]

更改分组的表格边界半径

是否有可能改变分组的UITableView的半径? 圆angular是我的devise激烈的方式。