我创build一个绘图iOS应用程序,我想创build一个“保存图像”方法。 绘图发生在touchesMoved:方法内。 – (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; [self drawToCache:touch]; [self setNeedsDisplay]; } – (void) drawToCache:(UITouch*)touch { hue += 0.005; if(hue > 1.0) hue = 0.0; UIColor *color = [UIColor colorWithHue:hue saturation:0.7 brightness:1.0 alpha:1.0]; CGContextSetStrokeColorWithColor(cacheContext, [color CGColor]); CGContextSetLineCap(cacheContext, kCGLineCapRound); CGContextSetLineWidth(cacheContext, 15); CGPoint lastPoint = [touch previousLocationInView:self]; CGPoint newPoint = […]
我有问题在我的绘图中实现“浮雕/阴影效果”。 手指画图function目前正在我的自定义UIView工作正常,下面是我的drawRect方法代码: 用所有方法编辑代码: – (void)drawRect:(CGRect)rect { CGPoint mid1 = midPoint(previousPoint1, previousPoint2); CGPoint mid2 = midPoint(currentPoint, previousPoint1); CGContextRef context = UIGraphicsGetCurrentContext(); [self.layer renderInContext:context]; CGContextMoveToPoint(context, mid1.x, mid1.y); CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y); CGContextSetLineCap(context, kCGLineCapRound); CGContextSetLineWidth(context, self.lineWidth); CGContextSetStrokeColorWithColor(context, self.lineColor.CGColor); CGContextSaveGState(context); // for shadow effects CGContextSetShadowWithColor(context, CGSizeMake(0, 2),3, self.lineColor.CGColor); CGContextStrokePath(context); [super drawRect:rect]; } CGPoint midPoint(CGPoint p1, CGPoint p2) { […]