IOS 自定义View 在上面如何画路径
IOS 自定义View 在上面怎么画路径
刚学ios 开发,之前搞android,我想在View上面绘制路径,按照我的手的滑动路径,目前只能是画一个直线,请大家指导下,API还不熟悉,谢谢了
------解决方案--------------------
LZ可以用UIBezierPath这个类。
具体使用的话可以这样:
刚学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]; }