在iPhone上通过手指触摸画一条直线

6

我不需要代码,但希望有关如何通过手指触摸在iPhone上绘制平滑线条的参考教程。

当用户绘制第二条线时,如何查找第二条线是否与第一条线相交。

谢谢!

1个回答

11

我正在使用这个:

   - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
      self.currentPath = [UIBezierPath bezierPath];
      currentPath.lineWidth = 3.0;
      [currentPath moveToPoint:[touch locationInView:self]];
      [paths addObject:self.currentPath];
    }

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
      [self.currentPath addLineToPoint:[touch locationInView:self]];
      [self setNeedsDisplay];
    }

    - (void)drawRect:(CGRect)rect {
      [[UIColor redColor] set];
      for (UIBezierPath *path in paths) {
        [path stroke];
      }
    }

你可以从文档中获取相关的类引用。


这对于画一条线来说没问题,但是在画完第一条线之后,我想画第二条线并找出第二条线是否与第一条线相交? - Mehul Mistri
1
请查看此链接:[link]http://iphoneobjectivec.blogspot.com/2011/01/drawing-line-on-touches-moved-in.html - Arvind

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接