读书人

IOS 自定义View 在上面如何画路径

发布时间: 2012-04-08 14:38:30 作者: rapoo

IOS 自定义View 在上面怎么画路径
刚学ios 开发,之前搞android,我想在View上面绘制路径,按照我的手的滑动路径,目前只能是画一个直线,请大家指导下,API还不熟悉,谢谢了

[解决办法]
LZ可以用UIBezierPath这个类。
具体使用的话可以这样:

C/C++ code
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {    UITouch *touch = [touches anyObject];    self.currentPath = [UIBezierPath bezierPath];    currentPath.lineWidth = 10.0;    [currentPath moveToPoint:[touch locationInView:self]];    [paths addObject:self.currentPath];}-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {    UITouch *touch = [touches anyObject];    [self.currentPath addLineToPoint:[touch locationInView:self]];    [self setNeedsDisplay];}-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {    UITouch *touch = [touches anyObject];        for (UIBezierPath *path in paths) {        [path removeAllPoints];    } 

读书人网 >Iphone

热点推荐