相关疑难解决方法(0)

如何使用Core Graphics创建浮雕或阴影效果(用于手指画)

我有问题在我的绘图中实现"浮雕/阴影效果".手指绘画功能目前与我的自定义工作正常,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)
{
    return CGPointMake((p1.x + p2.x) * 0.5, (p1.y + p2.y) * 0.5);
}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

    UITouch *touch = [touches anyObject]; …
Run Code Online (Sandbox Code Playgroud)

iphone core-graphics cgcontext ios cgcontextref

5
推荐指数
1
解决办法
979
查看次数

标签 统计

cgcontext ×1

cgcontextref ×1

core-graphics ×1

ios ×1

iphone ×1