【发布时间】:2012-10-02 12:35:04
【问题描述】:
我已经在我的应用程序中集成了画线。我没有使用过 OpenGL 或任何其他类似的框架。现在我想为这些线条添加发光效果。知道怎么做吗?
【问题讨论】:
标签: iphone objective-c ipad
我已经在我的应用程序中集成了画线。我没有使用过 OpenGL 或任何其他类似的框架。现在我想为这些线条添加发光效果。知道怎么做吗?
【问题讨论】:
标签: iphone objective-c ipad
使用 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]];
当你移动你的手指时,你会继续在你的 BezierPath 中添加这些点 in TouchMoved 方法如下
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
希望对你有帮助...
:)
【讨论】: