Tag: 核心graphics

预渲染的核心graphicsanimation不会顺利地animation和内存

我发布这个问题是为了回应我之前问题中的一个答案 : 多个CALayer掩码导致性能问题 所以,现在我试图按照预先渲染的animation方法,我仍然无法获得stream畅的animation。 不仅如此,在实际设备上运行时,由于内存问题,应用程序会定期崩溃。 你可以看到在这里运行的animation: http : //cl.ly/e3Qu (video看起来不那么糟糕,但是关注animation的边缘,在实际的设备上performance更差)。 这是我的代码: static CGFloat const animationDuration = 1.5; static CGFloat const calculationRate = (1.0/40.0); // 40fps max. static CGFloat const calculationCycles = animationDuration/calculationRate; @implementation splashView { CADisplayLink* l; CGImageRef backgroundImg; UIColor* color; NSMutableArray* animationImages; NSTimeInterval currentTime; } -(void) beginAnimating { static dispatch_once_t d; dispatch_once(&d, ^{ CGFloat […]

在iOS中绘制一个宽度可变的path

我正在写一个应用程序,我的写作工作正常,但是我想实现的是可变的笔画宽度 ,所以写作是非常现实和直观的,如“ BAMBOO ”和“ PENULTIMATE ”应用程序所做的。 首先,我想告诉你我曾经尝试过什么。 1)在iOS中,根据我的研究,它们没有压力检测或速度检测。 对于速度检测,我必须使用OPENGL。 2)由于这些限制,我尝试使用本教程中给出的方法,这是非常直接的。这里是链接http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-advanced-freehand-drawing-技术/ 3)这工作正常,但是这里发生的是,随着我移动速度越来越快,越来越慢,宽度越来越大。 但是我想要的是相反的效果,就是宽度应该随着移动速度的增加而增加,当我快速移动时,厚度只能看到边缘和整个线条。 这里是BAMBOO应用程序和我的应用程序的屏幕截图。 1)BAMBOO应用程序 在上面的图片中,线条的绘制速度很快,您会看到厚度仅在边缘。 2)我的APP 在这里,你会看到这条线在边缘更薄,而其他地方更厚。 所以,这是我的疑惑 1)除了我所尝试的之外,他们是否有更好的方法来满足我的要求? 2)如果我所尝试的是正确的解决问题的方法,那么我需要做出什么样的改变才能达到预期的效果。 关心Ranjit

为视网膜显示创build一个具有抗锯齿function的圆形或圆盘

我使用CoreGraphic CGContextFillEllipseInRect创build了一个圆。 我使用这个圆圈(实际上是一个磁盘)来replacethumbImage的UISlider 。 抗锯齿是默认应用的。 但是,我的iPhone 6的结果显然不好。 我可以清楚地看到像素,而不像抗锯齿closures,但比正常的UISlider的像素更多。 也许我做错了什么。 所以我的问题是,是否有一种方法来获得程序化的UISlider默认使用的相同的磁盘? 编辑: 以下是我如何创build磁盘: class func drawDisk(rgbValue:UInt32, rectForDisk: CGRect = CGRectMake(0.0, 0.0, 1.0, 1.0)) -> UIImage { let color = uicolorFromHex(rgbValue) UIGraphicsBeginImageContext(rectForDisk.size) let context = UIGraphicsGetCurrentContext() CGContextSetFillColorWithColor(context, color.CGColor) CGContextFillEllipseInRect(context, rectForDisk) let rectForCircle = CGRectMake(0.5, 0.5, rectForDisk.size.width – 1, rectForDisk.size.height – 1) CGContextSetLineWidth(context, 1.0) CGContextSetStrokeColorWithColor(context, UIColor.blackColor().CGColor) CGContextAddEllipseInRect(context, rectForCircle) […]

Coregraphics(iOS)中的内存pipe理

我正在绘制应用程序,我正在使用CGlayers进行绘图,所以我打开canvas,点击一个button, 我使用的UIBezierPath,然后将其转换为CGPath在touchesMoved下面,然后使用它来绘制 -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if (ctr == 4) { m_touchMoved = true; self.currentPath = [[DrawingPath alloc] init]; [self.currentPath setPathColor:self.lineColor]; self.currentPath.pathWidth = [NSString stringWithFormat:@"%f",self.lineWidth]; pts[3] = midPoint(pts[2], pts[4]);// move the endpoint to the middle of the line joining the second control point of the first Bezier segment and the first control point of […]

当在animation中调用块时停止填充颜色animation闪烁

我无法弄清楚为什么我的animation块完成后,animation从fromValue闪烁到toValue。 我知道在完成一个animation之后,您必须将CALayer的值设置为animation的结束状态,以保持animation的一致性。 然而,无论我把这些方法称为什么顺序,我总是得到闪烁的结果。 我正在做的是用biezerpath画一个复选标记,然后一旦strokeEndanimation完成,我通过animationfillColor属性填充复选标记。 填充复选标记function和复位复选标记function都是在用户选中与checkmark关联的tableviewcell的行时触发的。 噢,我正在使用AutoLayout,如果这有所作为。 所以我想知道一些事情实际上是一个1)一旦表格视图单元格被显示,我调用公共函数shoudSetCheckmarkToCheckedState设置布尔self.userSelectedCheckmark参数在函数中传递的isChecked。 从那里我调用[self setNeedsLayout],它触发layoutSubviews并调用shouldDrawCheckmark …函数。 我这样做的原因是因为如果我不第一次绘制单元格,就没有框架设置,所以我的绘图看起来很乱。 所以我应该每次我改变userSelectedCheckmark属性或者有更好的方法调用setNeedsLayout。 2)一旦animation完成,为什么复选标记闪烁。 我想我知道为什么,因为当animation完成时,图层属性被重置为与图层开始animation时相同的状态。 那么我该如何解决这个问题? 我只是触发一个计时器来改变animation结束前一毫秒的填充颜色,但是这并不正确。 inheritance人的代码btw typedef void (^animationCompletionBlock)(void); #define kAnimationCompletionBlock @"animationCompletionBlock" #import "CheckmarkView.h" #import "UIColor+HexString.h" @interface CheckmarkView() @property (nonatomic,strong) CAShapeLayer *checkmarkLayer; @property (nonatomic,assign) BOOL userSelectedCheckmark; – (void)shouldDrawCheckmarkToLayerWithAnimation:(BOOL)animateCheckmark; @end @implementation CheckmarkView #pragma mark – Lifecycle /**********************/ – (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) […]

使用核心animation来为StrokeColor设置animation

我试图animationCAShapeLayar的strokeColor属性。 我查看了整个文档,并指出这是一个可以animation的属性。 该代码正在为postion.yanimation,但不是strokeColor。 我会很高兴得到任何forms的帮助或build议 我用过的代码: lyr.fillColor = [[UIColor clearColor] CGColor]; lyr.lineWidth = 3.8; lyr.strokeColor = [[UIColor yellowColor] CGColor]; lyr.position = CGPointMake(160, 431); lyr.anchorPoint = CGPointMake(.5f, .5f); [self.view.layer addSublayer:lyr]; CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"strokeColor"]; basicAnimation.fromValue = [lyr valueForKey:@"strokeColor"]; basicAnimation.toValue =[NSValue valueWithPointer:[[UIColor clearColor] CGColor]]; basicAnimation.duration = 2; basicAnimation.repeatCount = 10; basicAnimation.autoreverses = YES; [lyr addAnimation:basicAnimation forKey:@"strokeColor"]; 在此先感谢,或。

iOS在形状的中心绘制文本

我试图在iOS中的形状中心绘制文本,例如Microsoft Office的插入形状请参阅: https : //www.dropbox.com/s/cgqyyuvy6hcv5g8/Screenshot%202014-01-21%2013.48.17巴纽 我有一个用于形成形状的坐标数组,这对创build实际的形状工作正常。 我的第一个策略是遵循这个stackoverflow问题: iOS上的不对称形状的核心文本,但我只能得到它在形状的底部绘制文本。 有什么方法可以垂直和水平居中文本? 然后我看了一下新的TextKit,但是我被困在如何inheritanceNSTextContainer接受一个CGPath或坐标数组来创build文本容器绘制里面。 我的备份解决scheme是使用“核心文本”在形状的中心坐标处绘制文本,但这会使文本在一些形状(如直angular三angular形)上绘制到形状外部。 另外,还有什么其他的方法可以用来在一个形状的中心有点文字? 谢谢, 丹妮尔。

CGImageCreateWithImageInRect不正确裁剪

我有一个时间使用CGImageCreateWithImageInRect裁剪照片。 我的应用程序有用户移动/放大图像,直到它填充316 x 316视图,然后我希望它裁剪框外的任何区域,并将图像保存为UIImage。 我通过获取x和y图像视图原点的绝对值来确定作物的原点,因为这将我带回到包含图像视图的视图/框的0,0。 以下是代码: CGRect croppedRect = CGRectMake(fabs(widthDistanceToOrigin), fabs(HeightDistanceToOrigin), 316, 316); CGImageRef croppedImageRef = CGImageCreateWithImageInRect(image.CGImage, croppedRect); UIImage *croppedImage = [UIImage imageWithCGImage: croppedImageRef scale: 1 / (imageScale) orientation: image.imageOrientation]; CGImageRelease(croppedImageRef); 这让我疯狂,我不能把它收割到我想要的地方。 我已经把它正确地缩放了,但是问题似乎与作物矩形的x和y原点有关,与它应该采取的区域相差太远(有时我会得到奇怪的结果)。 而且,对于手机相机拍摄的影像来说,我必须将我的作物中的所有东西都乘以2,因为它是正确的尺寸。 很奇怪。 所以我想知道,有没有人知道如何解决这个问题,或者有没有人有更好的裁剪方式(请记住,我需要在我的照片中裁剪一个区域)。 谢谢!

给定一个CGPath,如何使其曲线?

在以下屏幕截图中: 当您拖动单词气球的尾部(从气球连接到人嘴的东西)时,形状曲线(如图片中两个气球尾部之间的差异所示)。 我想知道,这是怎么做的? 我假设你需要从一个CGPath开始,做一些事情,有没有人碰巧知道这是什么? 更新:所以,如果我想曲线以下形状: 我会使用下面的代码: CGPathAddCurveToPoint(mutablePath, NULL, x1, y1, x2, y2 + constant, x5, y5); CGPathAddCurveToPoint(mutablePath, NULL, x3, y3, x4, y4 + constant, x5, y5); 常数重新调整点2和点4的y位置以形成曲线?

在Core Graphics中创build具有多个颜色段的圆

我正在试图绘制一个由相同大小的段组成的饼图,每个段都有不同的颜色。 我将我的代码放在这个SO上:在SWIFT中绘制一个圆形段的进度 let circlePath = UIBezierPath(ovalInRect: CGRect(x: 200, y: 200, width: 150, height: 150)) var segments: [CAShapeLayer] = [] let segmentAngle: CGFloat = 1.0 / CGFloat(totalSegments) for var i = 0; i < totalSegments; i++ { let circleLayer = CAShapeLayer() circleLayer.path = circlePath.CGPath // start angle is number of segments * the segment angle circleLayer.strokeStart […]