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

解决方案 »

  1.   

    LZ可以用UIBezierPath这个类。
    具体使用的话可以这样:-(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];
    }
      

  2.   

    上面的touchEnd方法里的removeAllPoints,楼主不必写。这是我自己要用到的。
      

  3.   

    感谢楼上的回答,UIBezierPath 是怎么实例化的呢?还有我想看下drawRect函数中的内容,谢谢了.
      

  4.   

    看到了 [UIBezierPath bezierPath];