4

我已经在我的应用程序中集成了画线。我没有使用过 OpenGL 或任何其他类似的框架。现在我想给这些线条一个发光效果。知道怎么做吗?

4

1 回答 1

2

使用 UIBezierPath 绘制线,如下面的代码......

您可以按如下方式初始化 UIBezierPath

    UIBezierPath *myPath=[[UIBezierPath alloc]init];
    myPath.lineWidth=10;
    brushPattern=[UIColor redColor]; //This is the color of my stroke

然后你有 Touch 方法来处理和跟踪你的触摸坐标。当您在屏幕上开始触摸时,您要求 UIBezierPath 移动到该触摸点

UITouch *mytouch=[[touches allObjects] objectAtInd
[myPath moveToPoint:[mytouch locationInView:self]];

当您四处移动手指时,您可以通过以下方式在 TouchMoved 方法中的 BezierPath 中继续添加这些点

UITouch *mytouch=[[touches allObjects] objectAtIndex:0];
[myPath addLineToPoint:[mytouch locationInView:self]];

由于我们需要不断的刷新屏幕,所以我们一绘制就出现在屏幕上,我们通过在 TouchMethod 中调用下面的方法来刷新 UIView 子类,这样一旦 BezierPath 有任何变化,它就会反映在屏幕。

[self setNeedsDisplay];

谈到为您完成所有绘图的 drawRect 方法,您需要在屏幕上设置笔画的颜色(笔画颜色是指在屏幕上完成绘画的颜色。)以及混合模式。您可以尝试不同的混合模式并查看结果。

- (void)drawRect:(CGRect)rect
{
    [brushPattern setStroke];
    [myPath strokeWithBlendMode:kCGBlendModeNormal alpha:1.0];

}

另请参阅下面的链接..

http://soulwithmobiletechnology.blogspot.in/2011/05/uibezierpath-tutorial-for-iphone-sdk-40.html

我希望这可以帮助你...

:)

于 2012-10-02T12:40:27.613 回答