如何在iPad App中使用Glow效果绘制线条 [英] How to Draw lines with Glow effect in iPad App

查看:112
本文介绍了如何在iPad App中使用Glow效果绘制线条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have integrated drawing a line in my application. I have not used OpenGl or any other similar framework. Now I want to give a glow effect to these lines. Any idea how to do that?

推荐答案

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

use UIBezierPath for draw line like below code...

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

You can init the UIBezierPath as following

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

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

Then you have Touch methods which handle and track the coordinates of your touch. When your touch begins on the screen, you ask UIBezierPath to move to that touch point

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

当您移动手指时,您可以通过以下方式在TouchMoved方法中的BezierPath中添加这些点/ p>

As you move your finger around, you keep adding those points in your BezierPath in TouchMoved method by following

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

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

As we need constant refreshing of the screen, so that as soon as we draw it appears on the screen, we refresh the UIView subclass by calling following method in TouchMethod so that as soon as there any change in the BezierPath, it is reflected on the screen.

[self setNeedsDisplay];

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

Talking about drawRect Method which does all the drawing for you, you need to set the color of your stroke(stroke color means the color with which painting will be done on screen.) on screen and also the blend mode. You can try different blend mode and see the result.

- (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

我希望这会对你有所帮助...

I hope this helps you...

:)

这篇关于如何在iPad App中使用Glow效果绘制线条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆